Adding "Mark Gone" capability to effectively remove a slug. #18

Open
wants to merge 1 commit into
from

3 participants

@benschell

Enhances Lessnmore to have "Mark Gone" support. This was already demarcated in index.php, but wasn't functional.

I've added this to the Stats page for administration and implemented the TODO.

@keith

This doesn't seem to work with the newest Stats page.

@alanhogan alanhogan commented on the diff Jan 30, 2015
-/index.php
@@ -550,7 +550,24 @@ function bc_log($message){
}
elseif(isset($_GET['mark_gone']) && isset($_GET['slug']) && strlen(trim($_GET['slug'])))
{ // Mark a redirection as GONE
- // TODO
+ $prefix = DB_PREFIX;
+ $slug = $_GET['slug'];
+
+ // Check if slug is in use
+ $stmt = $db->prepare("SELECT url, checksum, custom_url, redir_type FROM {$prefix}urls WHERE BINARY custom_url = BINARY :slug AND custom_url = :slug");
+ $stmt->execute(array('slug'=>$slug));
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ if($row){ // slug exists
+ $result = bcurls_update_slug($row['url'], $row['checksum'], $row['custom_url'], 'gone');
+ if($result !== true) {
+ $error = $insert_result;
@alanhogan
Owner
alanhogan added a line comment Jan 30, 2015

Where does $insert_result come from? is this a magic PHP thing or a typo for $result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alanhogan alanhogan commented on the diff Jan 30, 2015
-/index.php
+ $slug = $_GET['slug'];
+
+ // Check if slug is in use
+ $stmt = $db->prepare("SELECT url, checksum, custom_url, redir_type FROM {$prefix}urls WHERE BINARY custom_url = BINARY :slug AND custom_url = :slug");
+ $stmt->execute(array('slug'=>$slug));
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ if($row){ // slug exists
+ $result = bcurls_update_slug($row['url'], $row['checksum'], $row['custom_url'], 'gone');
+ if($result !== true) {
+ $error = $insert_result;
+ include('pages/error.php');
+ exit;
+ }
+ }
+ // Redirect to the stats page
+ header('Location:?stats=1');
@alanhogan
Owner
alanhogan added a line comment Jan 30, 2015

This makes sense in the UI but not as for API usages. Let's check the case, like above:

if (isset($_GET['api']))
    {
           echo 'deleted';
           exit;
    }
else
    {
        header('Location: ?stats=1');
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alanhogan
Owner

@benschell so embarrassed i didn't look at this for so long. Comments welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment