Skip to content

Commit

Permalink
Bug fix; see: wpsharks/comet-cache#541
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Aug 5, 2015
1 parent 5f06e11 commit 235eeaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/includes/classes/VsUpgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function fromLt140605()
$this->plugin->options['base_dir'] = $this->plugin->default_options['base_dir'];
}
if ($existing_options['cache_dir']) {
$this->plugin->wipeCache(false, ABSPATH.$existing_options['cache_dir']);
$this->plugin->deleteAllFilesDirsIn(ABSPATH.$existing_options['cache_dir'], true);
}
unset($this->plugin->options['cache_dir']); // Just to be sure.

Expand Down Expand Up @@ -136,7 +136,7 @@ protected function fromLt140612()
|| is_array($existing_options = get_option('quick_cache_options'))
) {
if (!empty($existing_options['base_dir']) && stripos($existing_options['base_dir'], basename(WP_CONTENT_DIR)) !== false) {
$this->plugin->wipeCache(false, ABSPATH.$existing_options['base_dir']);
$this->plugin->deleteAllFilesDirsIn(ABSPATH.$existing_options['base_dir'], true);
$this->plugin->options['base_dir'] = $this->plugin->default_options['base_dir'];

update_option(GLOBAL_NS.'_options', $this->plugin->options);
Expand Down
32 changes: 15 additions & 17 deletions src/includes/closures/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$self->addAdvancedCache();
$self->updateBlogPaths();
}
$self->wipeCache(); // Always wipe the cache; unless disabled by site owner; @see disableAutoWipeCacheRoutines()
$self->wipeCache(); // Fresh start now.

$self->enqueueNotice(sprintf(__('<strong>%1$s:</strong> detected a new version of itself. Recompiling w/ latest version... wiping the cache... all done :-)', SLUG_TD), esc_html(NAME)), '', true);
};
Expand Down Expand Up @@ -88,7 +88,7 @@
}
$self->removeWpCacheFromWpConfig();
$self->removeAdvancedCache();
$self->wipeCache();
$self->wipeCache(); // Full wipe now.

if (!$self->options['uninstall_on_deletion']) {
return; // Nothing to do here.
Expand Down Expand Up @@ -397,10 +397,6 @@ function ($string) {
if (!is_writable($advanced_cache_file)) {
return false; // Not possible.
}
// Ignore; this is created by ZenCache; and we don't need to obey in this case.
#if(defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS)
# return FALSE; // We may NOT edit any files.

/* Empty the file only. This way permissions are NOT lost in cases where
a site owner makes this specific file writable for ZenCache. */
if (file_put_contents($advanced_cache_file, '') !== 0) {
Expand All @@ -419,17 +415,19 @@ function ($string) {
* @note The `advanced-cache.php` file is deleted by this routine.
*/
$self->deleteAdvancedCache = function () use ($self) {
$advanced_cache_file = WP_CONTENT_DIR.'/advanced-cache.php';
$cache_dir = $self->cacheDir();
$advanced_cache_check_file = $cache_dir.'/zc-advanced-cache';
$advanced_cache_file = WP_CONTENT_DIR.'/advanced-cache.php';

if (!is_file($advanced_cache_file)) {
return true; // Already gone.
if (is_file($advanced_cache_file)) {
if (!is_writable($advanced_cache_file) || !unlink($advanced_cache_file)) {
return false; // Not possible; or outright failure.
}
}
// Ignore; this is created by ZenCache; and we don't need to obey in this case.
#if(defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS)
# return FALSE; // We may NOT edit any files.

if (!is_writable($advanced_cache_file) || !unlink($advanced_cache_file)) {
return false; // Not possible; or outright failure.
if (is_file($advanced_cache_check_file)) {
if (!is_writable($advanced_cache_check_file) || !unlink($advanced_cache_check_file)) {
return false; // Not possible; or outright failure.
}
}
return true; // Deletion success.
};
Expand Down Expand Up @@ -482,8 +480,7 @@ function ($string) {
* @note While this routine is attached to a WP filter, we also call upon it directly at times.
*/
$self->updateBlogPaths = function ($enable_live_network_counts = null) use ($self) {
$value = // This hook actually rides on a filter.
$enable_live_network_counts; // Filter value.
$value = $enable_live_network_counts; // This hook actually rides on a filter.

if (!$self->options['enable']) {
return $value; // Nothing to do.
Expand All @@ -506,6 +503,7 @@ function ($string) {

foreach ($paths as &$_path) {
// Strip base; these need to match `$host_dir_token`.
// @TODO is it necessary to remove the base token here?
$_path = '/'.ltrim(preg_replace('/^'.preg_quote($self->hostBaseToken(), '/').'/', '', $_path), '/');
}
unset($_path); // Housekeeping.
Expand Down
13 changes: 3 additions & 10 deletions src/includes/closures/Plugin/WcpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,22 @@
*
* @since 150422 Rewrite.
*
* @param bool $manually Defaults to a `FALSE` value.
* Pass as TRUE if the wipe is done manually by the site owner.
* @param string $also_wipe_dir Defaults to an empty string; i.e., only wipe {@link $cache_sub_dir} files.
* @param bool $manually TRUE if the wipe is done manually by the site owner.
*
* @throws \Exception If a wipe failure occurs.
*
* @return int Total files wiped by this routine (if any).
*/
$self->wipeCache = function ($manually = false, $also_wipe_dir = '') use ($self) {
$self->wipeCache = function ($manually = false) use ($self) {
$counter = 0; // Initialize.

$also_wipe_dir = trim((string) $also_wipe_dir);

if (!$manually && $self->disableAutoWipeCacheRoutines()) {
return $counter; // Nothing to do.
}
@set_time_limit(1800); // @TODO Display a warning.

if (is_dir($cache_dir = $self->cacheDir())) {
$counter += $self->deleteAllFilesDirsIn($cache_dir);
}
if ($also_wipe_dir && is_dir($also_wipe_dir)) {
$counter += $self->deleteAllFilesDirsIn($also_wipe_dir);
$counter += $self->deleteFilesFromCacheDir('/^.+/i');
}
/*[pro strip-from="lite"]*/
$counter += $self->wipeHtmlCCache($manually);
Expand Down

0 comments on commit 235eeaa

Please sign in to comment.