google-code-export / stikked

Automatically exported from code.google.com/p/stikked
GNU General Public License v3.0
1 stars 1 forks source link

checkPaste could check whether the paste is expired #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Like I said in the group:

"The checkPaste method in the pastes model can be modified to delete the
paste and return false, if the paste is due to expire. "

Original issue reported on code.google.com by perrytri...@gmail.com on 18 May 2008 at 5:05

Attachments:

GoogleCodeExporter commented 9 years ago
Great Idea!

Original comment by b...@mycodenow.com on 5 Jul 2008 at 10:28

GoogleCodeExporter commented 9 years ago

Original comment by ben%benm...@gtempaccount.com on 11 Feb 2009 at 11:59

GoogleCodeExporter commented 9 years ago
Here's the code again for the modified checkPastes method:

    function checkPaste($seg=2) {
        if($this->uri->segment($seg) == ""){
            return FALSE;
        } else {
            $this->db->where("pid", $this->uri->segment($seg));
            $query = $this->db->get("pastes");

            if($query->num_rows() > 0) {
                $paste = $query->row_array();
                if ( $paste['expire'] < time() ) {
                    $this->db->delete('pastes',array('pid'=>$paste['pid']));
                    return FALSE;
                } else {
                    return TRUE;
                }
            } else {
                return FALSE;
            }
        }
    }

I realize that my earlier patch was probably not used because it also contained
changes to other methods, that relied on other features etc... I'm new to this, 
so I
didn't consider that the patch should be completely atomic, and not have other
dependencies. If you want the checkPaste method to handle deleting, the method 
above
should work, but note that that is copied and pasted from an earlier release of
Stikked that I was working on. You may need to make slight changes to be 
compatible
with the current release.

Original comment by michelle...@gmail.com on 15 Feb 2009 at 6:04

GoogleCodeExporter commented 9 years ago
That was actually me, not my wife Michelle!

Original comment by perrytri...@gmail.com on 15 Feb 2009 at 6:26

GoogleCodeExporter commented 9 years ago
I think the if statement should be :

if ( $paste['expire'] < time() && $paste['expire']!=0)

Since Stikked assigns a default expiration time of 0, $paste['expire']!=0 is 
needed so that pastes marked "Keep Forever" won't be deleted, as time() is 
always greater than 0. 

This code works with current (0.5.4) version. 

Original comment by Rick...@gmail.com on 12 Jan 2012 at 12:03