Skip to content

Commit

Permalink
Wipe old qc-c- cache files too.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasWSInc committed Apr 26, 2014
1 parent 8a08877 commit 8c7a3ef
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions quick-cache-pro/quick-cache-pro.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,12 +956,12 @@ public function wipe_cache($manually = FALSE)
/** @var $_dir_file \RecursiveDirectoryIterator For IDEs. */
foreach($this->dir_regex_iteration($cache_dir, '/.+/') as $_dir_file)
{
if(($_dir_file->isFile() || $_dir_file->isLink()) && strpos($_dir_file->getSubpathname(), '/') !== FALSE)
// Don't delete files in the immediate directory; e.g. `qc-advanced-cache` or `.htaccess`, etc.
if(($_dir_file->isFile() || $_dir_file->isLink()) && (strpos($_dir_file->getSubPathname(), '/') !== FALSE || strpos($_dir_file->getSubPathname(), 'qc-c-') === 0))
// Don't delete files in the immediate directory; e.g. `qc-advanced-cache` or `.htaccess`, etc. ~ With one exception for old `qc-c-` cache files.
// Actual `http|https/...` cache files are nested. Files in the immediate directory are for other purposes.
if(!unlink($_dir_file->getPathname())) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to wipe file: `%1$s`.', $this->text_domain), $_dir_file->getPathname()));
else $counter++; // Increment counter for each file we purge.
else $counter++; // Increment counter for each file we wipe.

else if($_dir_file->isDir()) // Directories are last in the iteration.
if(!rmdir($_dir_file->getPathname())) // Throw exception if unable to delete.
Expand Down Expand Up @@ -1229,7 +1229,7 @@ public function auto_clear_cache()
* @since 140422 First documented version.
*
* @param integer $id A WordPress post ID.
* @param bool $force Defaults to a `FALSE` value.
* @param bool $force Defaults to a `FALSE` value.
* Pass as TRUE if purge should be done for `draft`, `pending`,
* or `future` post statuses.
*
Expand Down Expand Up @@ -1318,9 +1318,9 @@ public function auto_purge_post_cache($id, $force = FALSE)
*
* @since 14xxxx First documented version.
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param object $post Post object.
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param object $post Post object.
*
* @return integer Total files purged by this routine (if any).
*
Expand All @@ -1331,20 +1331,21 @@ public function auto_purge_post_cache($id, $force = FALSE)
*
* @see auto_purge_comment_post_cache()
*/
public function auto_purge_post_cache_transition($new_status, $old_status, $post) {
$counter = 0; // Initialize.
public function auto_purge_post_cache_transition($new_status, $old_status, $post)
{
$counter = 0; // Initialize.

if(!$this->options['enable'])
return $counter; // Nothing to do.
if(!$this->options['enable'])
return $counter; // Nothing to do.

if($old_status !== 'publish' && $old_status !== 'private')
return $counter; // Nothing to do.
if($old_status !== 'publish' && $old_status !== 'private')
return $counter; // Nothing to do.

if($new_status === 'draft' || $new_status === 'future' || $new_status === 'private')
$counter = $this->auto_purge_post_cache($post->ID, TRUE);
if($new_status === 'draft' || $new_status === 'future' || $new_status === 'private')
$counter = $this->auto_purge_post_cache($post->ID, TRUE);

return apply_filters(__METHOD__, $counter, get_defined_vars());
}
return apply_filters(__METHOD__, $counter, get_defined_vars());
}

/**
* Automatically purges cache files for the home page.
Expand Down Expand Up @@ -1559,7 +1560,7 @@ public function auto_purge_post_terms_cache($id)
* Build an array of terms with Term Names, Permalinks, and associated Taxonomy labels
*/
$terms_to_purge = array();
$_i = 0;
$_i = 0;
foreach($terms as $_term)
{
if(($_link = get_term_link($_term)))
Expand Down Expand Up @@ -1893,6 +1894,8 @@ public function remove_wp_cache_from_wp_config()
*
* @since 140422 First documented version.
*
* @attaches-to `init` hook.
*
* @note This runs so that remote deployments which completely wipe out an
* existing set of website files (like the AWS Elastic Beanstalk does) will NOT cause Quick Cache
* to stop functioning due to the lack of an `advanced-cache.php` file, which is generated by Quick Cache.
Expand Down Expand Up @@ -2106,6 +2109,8 @@ public function delete_advanced_cache()
*
* @since 140422 First documented version.
*
* @attaches-to `init` hook.
*
* @note This runs so that remote deployments which completely wipe out an
* existing set of website files (like the AWS Elastic Beanstalk does) will NOT cause Quick Cache
* to stop functioning due to the lack of a `qc-blog-paths` file, which is generated by Quick Cache.
Expand Down

0 comments on commit 8c7a3ef

Please sign in to comment.