<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Deleting records with a limited life time</title>
	<atom:link href="http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Thu, 11 Mar 2010 15:41:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-109646</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Thu, 09 Oct 2008 18:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-109646</guid>
		<description>@Brett: Yes, that&#039;s a feasible way, too. Thanks for sharing!</description>
		<content:encoded><![CDATA[<p>@Brett: Yes, that&#8217;s a feasible way, too. Thanks for sharing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brett ODonnell</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-109581</link>
		<dc:creator>Brett ODonnell</dc:creator>
		<pubDate>Thu, 09 Oct 2008 10:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-109581</guid>
		<description>I prefer to use strtotime() like this:

&lt;code&gt;
// in the RequestToken model
public function deleteExpired() {
    $this-&gt;deleteAll(array(&#039;RequestToken.modified &lt;=&#039; =&gt; date(&#039;Y-m-d H:i:s&#039;,strtotime(&#039;-24 hours&#039;))));
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I prefer to use strtotime() like this:</p>
<pre><code>// in the RequestToken model
public function deleteExpired() {
    $this-&gt;deleteAll(array('RequestToken.modified &lt;=' =&gt; date('Y-m-d H:i:s',strtotime('-24 hours'))));
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-109200</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 07 Oct 2008 09:29:22 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-109200</guid>
		<description>@Pixelastic: Yes, as soon as your server is in a different timezone than your visitors and you want to show them date-related things it becomes tricky. 

One approach is, as you did, to deal with all date-related stuff directly in PHP. A different approach could be to work with the difference between the timezone of the server and the timezone of the visitors. Everytime you read dates from the database you add/subtract the difference. 

But I have to admit that I don&#039;t have any real experience with such scenarios...</description>
		<content:encoded><![CDATA[<p>@Pixelastic: Yes, as soon as your server is in a different timezone than your visitors and you want to show them date-related things it becomes tricky. </p>
<p>One approach is, as you did, to deal with all date-related stuff directly in PHP. A different approach could be to work with the difference between the timezone of the server and the timezone of the visitors. Everytime you read dates from the database you add/subtract the difference. </p>
<p>But I have to admit that I don&#8217;t have any real experience with such scenarios&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pixelastic</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-109130</link>
		<dc:creator>Pixelastic</dc:creator>
		<pubDate>Mon, 06 Oct 2008 17:17:10 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-109130</guid>
		<description>As I&#039;ve just realized, uploading my app from prod to dev, this approach seems to have its limits when your mysql server is in another timezone than your visitors.

I have a site where items are displayed based on the time they where modified (auto-populated field modified of cakePHP).

First problem, dates were stored in the database according to the server where PHP were running. 
I had to change the timezone used by php by putting a SetEnv TZ Europe/Paris in my .htaccess and a date_default_timezone_set(&#039;Europe/Paris&#039;); in my bootstrap.php to correct that.

But as my app is running on a shared server, I can&#039;t change the mysql timezone (only root can do that), thus can&#039;t use mysql built-in NOW(), INTERVAL() and such functions.
So I had to re-re-write back all my SELECT queries, using php generated dates instead of mysql built-in ones.

Or maybe did I overlooked something ?</description>
		<content:encoded><![CDATA[<p>As I&#8217;ve just realized, uploading my app from prod to dev, this approach seems to have its limits when your mysql server is in another timezone than your visitors.</p>
<p>I have a site where items are displayed based on the time they where modified (auto-populated field modified of cakePHP).</p>
<p>First problem, dates were stored in the database according to the server where PHP were running.<br />
I had to change the timezone used by php by putting a SetEnv TZ Europe/Paris in my .htaccess and a date_default_timezone_set(&#8216;Europe/Paris&#8217;); in my bootstrap.php to correct that.</p>
<p>But as my app is running on a shared server, I can&#8217;t change the mysql timezone (only root can do that), thus can&#8217;t use mysql built-in NOW(), INTERVAL() and such functions.<br />
So I had to re-re-write back all my SELECT queries, using php generated dates instead of mysql built-in ones.</p>
<p>Or maybe did I overlooked something ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-106657</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 16 Sep 2008 15:57:08 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-106657</guid>
		<description>@Rafael, Pixelastic: Thanks for your comments!

@Rafael: Yes, the date and time functions are very powerful. 

I don&#039;t know the official name of that pattern, but I think it is a kind of a facade. And yes, it is a possible way for the implementation. Personally, I&#039;m not a big fan of using this approach to reduce the number of public methods of a class, as it makes your API implicit, i.e. you have to look in the source or the documentation to figure out what the method does...</description>
		<content:encoded><![CDATA[<p>@Rafael, Pixelastic: Thanks for your comments!</p>
<p>@Rafael: Yes, the date and time functions are very powerful. </p>
<p>I don&#8217;t know the official name of that pattern, but I think it is a kind of a facade. And yes, it is a possible way for the implementation. Personally, I&#8217;m not a big fan of using this approach to reduce the number of public methods of a class, as it makes your API implicit, i.e. you have to look in the source or the documentation to figure out what the method does&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pixelastic</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-106603</link>
		<dc:creator>Pixelastic</dc:creator>
		<pubDate>Mon, 15 Sep 2008 19:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-106603</guid>
		<description>Nice one, I was trying to do the same thing by using the array(&#039;conditions&#039; =&gt; array()) syntax but it didn&#039;t work because fields were treated as string (and escaped with &#039;)

I had to make my calculation directly in php with mktime() and date() before putting it in the query, but your approach is nice</description>
		<content:encoded><![CDATA[<p>Nice one, I was trying to do the same thing by using the array(&#8216;conditions&#8217; =&gt; array()) syntax but it didn&#8217;t work because fields were treated as string (and escaped with &#8216;)</p>
<p>I had to make my calculation directly in php with mktime() and date() before putting it in the query, but your approach is nice</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rafaelbandeira3</title>
		<link>http://cakebaker.42dh.com/2008/09/15/deleting-records-with-a-limited-life-time/comment-page-1/#comment-106598</link>
		<dc:creator>rafaelbandeira3</dc:creator>
		<pubDate>Mon, 15 Sep 2008 18:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=814#comment-106598</guid>
		<description>good one Daniel, docs on MySQL Date and Time functions are a must-read for every dev. In my current - and endless - project I moved lots of time and date handling from the app layer - good &amp; old php - to db queries, and I must say, the gain is not only on performance but in readability and api size for models. 

Now just a buggy thought: Why not follow the pattern jQuery follows - I don&#039;t know if it has a name - and that we already do with Model::find(), letting all related operations in just one method, then your method would be more like:

&lt;code&gt;
function deleteAll($conditions, $cascade = true, $callbacks = false) {
     if($conditions === &#039;expired&#039;) {
          $conditions = array(&#039;RequestToken.modified &lt;= DATE_SUB(NOW(), INTERVAL 24 HOUR)&#039;);
     } elseif($conditions === &#039;invalid&#039;) {
          $conditions = array(&#039;CheeseCake.flavor != &quot;cheese&quot;&#039;);
     }
     return parent::deleteAll($conditions, $cascade, $callbacks);
}
&lt;/code&gt;

What do you think? I think it&#039;s nice</description>
		<content:encoded><![CDATA[<p>good one Daniel, docs on MySQL Date and Time functions are a must-read for every dev. In my current &#8211; and endless &#8211; project I moved lots of time and date handling from the app layer &#8211; good &amp; old php &#8211; to db queries, and I must say, the gain is not only on performance but in readability and api size for models. </p>
<p>Now just a buggy thought: Why not follow the pattern jQuery follows &#8211; I don&#8217;t know if it has a name &#8211; and that we already do with Model::find(), letting all related operations in just one method, then your method would be more like:</p>
<pre><code>function deleteAll($conditions, $cascade = true, $callbacks = false) {
     if($conditions === 'expired') {
          $conditions = array('RequestToken.modified &lt;= DATE_SUB(NOW(), INTERVAL 24 HOUR)');
     } elseif($conditions === 'invalid') {
          $conditions = array('CheeseCake.flavor != "cheese"');
     }
     return parent::deleteAll($conditions, $cascade, $callbacks);
}</code></pre>
<p>What do you think? I think it&#8217;s nice</p>
]]></content:encoded>
	</item>
</channel>
</rss>
