Permalink
Browse files

MINOR added locking to static publisher to avoid two queues running a…

…t the same time. (from r87792) (from r98164)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@102757 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent d87a652 commit 6c300f5659abe3a85f6f1092ce093f0bb729b2dc @chillu chillu committed Apr 14, 2010
Showing with 9 additions and 2 deletions.
  1. +1 −0 code/LeftAndMain.php
  2. +8 −2 tasks/RebuildStaticCacheTask.php
View
1 code/LeftAndMain.php
@@ -971,6 +971,7 @@ public function printable() {
* @return int
*/
public function currentPageID() {
+ SS_Backtrace::backtrace();
if($this->request->getVar('ID')) {
return $this->request->getVar('ID');
} elseif ($this->request->param('ID') && is_numeric($this->request->param('ID'))) {
View
10 tasks/RebuildStaticCacheTask.php
@@ -44,6 +44,11 @@ function rebuildCache($urls, $removeAll = true) {
echo "Rebuilding cache.\nNOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.\n\n";
$page = singleton('Page');
+ $cacheBaseDir = $page->getDestDir();
+
+ if (file_exists($cacheBaseDir.'/lock') && !isset($_REQUEST['force'])) die("There already appears to be a publishing queue running. You can skip warning this by adding ?/&force to the URL.");
+
+ touch($cacheBaseDir.'/lock');
foreach($urls as $i => $url) {
if($url && !is_string($url)) {
@@ -68,8 +73,6 @@ function rebuildCache($urls, $removeAll = true) {
if(!isset($_GET['urls']) && $start == 0 && file_exists("../cache")) {
echo "Removing stale cache files... \n";
flush();
- $cacheBaseDir = $page->getDestDir();
-
if (FilesystemPublisher::$domain_based_caching) {
// Glob each dir, then glob each one of those
foreach(glob(BASE_PATH . '/cache/*', GLOB_ONLYDIR) as $cacheDir) {
@@ -89,6 +92,9 @@ function rebuildCache($urls, $removeAll = true) {
}
echo "Rebuilding cache from " . sizeof($mappedUrls) . " urls...\n\n";
$page->extend('publishPages', $mappedUrls);
+
+ if (file_exists($cacheBaseDir.'/lock')) unlink($cacheBaseDir.'/lock');
+
echo "\n\n== Done! ==";
}

0 comments on commit 6c300f5

Please sign in to comment.