Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wipe old qc-c- cache files too. #131

Merged
merged 1 commit into from
Apr 28, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions quick-cache/quick-cache.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,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 @@ -813,7 +813,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 @@ -902,9 +902,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 @@ -915,20 +915,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 @@ -1143,7 +1144,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 @@ -1342,6 +1343,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 @@ -1518,6 +1521,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