Note that there are some explanatory texts on larger screens.

plurals
  1. POautomated backup issue with directory
    text
    copied!<p>I run my own backup class. In it I have a maintenance function that checks if the user is an admin, checks if the user is on the homepage, then scans the backup dir to see if the site has not been backed up in a day by checking the file created timestamp. If the condition exists where the files, or lack thereof are over a day old, it initiates a backup and notifies the user.</p> <p>This was working fine before I ported it to a class (not sure if I messed anything up along the way). For debugging purposes I added a few echos .etc.</p> <p>The problem is that the maintenance script does not do anything if the dir is empty (meaning there needs to be a backup or if <code>$latest_filename</code> is not set). All my debugging has led me to believe that the latter variable is always evaluating to <code>set</code> even if the dir is empty.</p> <pre><code> if ($frontpage &amp;&amp; checkAdmin()) { $path = $this-&gt;dir_sql; $latest_ctime = 0; $latest_filename = ''; $d = dir($path); while (false !== ($entry = $d-&gt;read())) { $filepath = "{$path}/{$entry}"; // could do also other checks than just checking whether the entry is a file if (is_file($filepath) &amp;&amp; filectime($filepath) &gt; $latest_ctime) { $latest_ctime = filectime($filepath); $latest_filename = $entry; echo $latest_filename; echo $latest_ctime; } } // check if latest backup is over a day old // if it is create a new backup and run the regular // maintenance scripts below if (is_file($latest_filename) &amp;&amp; date('d', filectime($latest_filename)) == date('d')) { self::doBackup(); } elseif(!isset($latest_filename)) { self::doBackup(); } } </code></pre> <p>Edit/update:</p> <p>I just added <code>if (isDirEmpty($this-&gt;dir_sql)) { self::doBackup(); } </code> before the if, and removed the elseif at the bottom, which did the trick, but still weird.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload