mirror of
https://github.com/silverstripe/silverstripe-staticpublisher
synced 2024-10-22 14:05:54 +02:00
FIX: leave trailing slashes along.
This commit is contained in:
parent
9b39e069a8
commit
410ded98b2
@ -58,7 +58,10 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->destFolder = $destFolder;
|
$this->destFolder = $destFolder;
|
||||||
$this->fileExtension = $fileExtension;
|
|
||||||
|
if($fileExtension) {
|
||||||
|
$this->fileExtension = $fileExtension;
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -169,6 +172,7 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
// This may have been set explicitly via StaticPublisher::static_publisher_theme,
|
// This may have been set explicitly via StaticPublisher::static_publisher_theme,
|
||||||
// or we can use the last non-null theme.
|
// or we can use the last non-null theme.
|
||||||
$customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme');
|
$customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme');
|
||||||
|
|
||||||
if(!$customTheme) {
|
if(!$customTheme) {
|
||||||
Config::inst()->update('SSViewer', 'theme', Config::inst()->get('SSViewer', 'custom_theme'));
|
Config::inst()->update('SSViewer', 'theme', Config::inst()->get('SSViewer', 'custom_theme'));
|
||||||
} else {
|
} else {
|
||||||
@ -196,9 +200,16 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
|
|
||||||
foreach($urls as $url => $path) {
|
foreach($urls as $url => $path) {
|
||||||
$origUrl = $url;
|
$origUrl = $url;
|
||||||
$result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null);
|
$result[$origUrl] = array(
|
||||||
|
'statuscode' => null,
|
||||||
|
'redirect' => null,
|
||||||
|
'path' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
if($staticBaseUrl) {
|
||||||
|
Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if($staticBaseUrl) Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl);
|
|
||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
if($url && !is_string($url)) {
|
if($url && !is_string($url)) {
|
||||||
|
@ -8,6 +8,7 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
StaticPublisher::set_echo_progress(true);
|
StaticPublisher::set_echo_progress(true);
|
||||||
|
|
||||||
$page = singleton('Page');
|
$page = singleton('Page');
|
||||||
|
|
||||||
if(!$page->hasMethod('allPagesToCache')) {
|
if(!$page->hasMethod('allPagesToCache')) {
|
||||||
user_error(
|
user_error(
|
||||||
'RebuildStaticCacheTask::index(): Please define a method "allPagesToCache()" on your Page class to return all pages affected by a cache refresh.',
|
'RebuildStaticCacheTask::index(): Please define a method "allPagesToCache()" on your Page class to return all pages affected by a cache refresh.',
|
||||||
@ -16,8 +17,11 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!empty($_GET['urls'])) $urls = $_GET['urls'];
|
if(!empty($_GET['urls'])) {
|
||||||
else $urls = $page->allPagesToCache();
|
$urls = $_GET['urls'];
|
||||||
|
} else {
|
||||||
|
$urls = $page->allPagesToCache();
|
||||||
|
}
|
||||||
|
|
||||||
$this->rebuildCache($urls, true);
|
$this->rebuildCache($urls, true);
|
||||||
}
|
}
|
||||||
@ -28,7 +32,7 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
* @param array $urls The URLs of pages to re-fetch and cache.
|
* @param array $urls The URLs of pages to re-fetch and cache.
|
||||||
* @param bool $removeAll Remove all stale cache files (default TRUE).
|
* @param bool $removeAll Remove all stale cache files (default TRUE).
|
||||||
*/
|
*/
|
||||||
function rebuildCache($urls, $removeAll = true) {
|
public function rebuildCache($urls, $removeAll = true) {
|
||||||
|
|
||||||
if(!is_array($urls)) {
|
if(!is_array($urls)) {
|
||||||
// $urls must be an array
|
// $urls must be an array
|
||||||
@ -37,6 +41,7 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if(!Director::is_cli()) echo "<pre>\n";
|
if(!Director::is_cli()) echo "<pre>\n";
|
||||||
|
|
||||||
echo "Rebuilding cache.\nNOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.\n\n";
|
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');
|
$page = singleton('Page');
|
||||||
@ -46,7 +51,9 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
Filesystem::makeFolder($cacheBaseDir);
|
Filesystem::makeFolder($cacheBaseDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.");
|
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');
|
touch($cacheBaseDir.'/lock');
|
||||||
|
|
||||||
@ -57,11 +64,9 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove leading slashes from all URLs (apart from the homepage)
|
|
||||||
if(substr($url,-1) == '/' && $url != '/') $url = substr($url,0,-1);
|
|
||||||
|
|
||||||
$urls[$i] = $url;
|
$urls[$i] = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$urls = array_unique($urls);
|
$urls = array_unique($urls);
|
||||||
sort($urls);
|
sort($urls);
|
||||||
|
|
||||||
@ -69,14 +74,18 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
|
|
||||||
$start = isset($_GET['start']) ? $_GET['start'] : 0;
|
$start = isset($_GET['start']) ? $_GET['start'] : 0;
|
||||||
$count = isset($_GET['count']) ? $_GET['count'] : sizeof($urls);
|
$count = isset($_GET['count']) ? $_GET['count'] : sizeof($urls);
|
||||||
if(($start + $count) > sizeof($urls)) $count = sizeof($urls) - $start;
|
|
||||||
|
if(($start + $count) > sizeof($urls)) {
|
||||||
|
$count = sizeof($urls) - $start;
|
||||||
|
}
|
||||||
|
|
||||||
$urls = array_slice($urls, $start, $count);
|
$urls = array_slice($urls, $start, $count);
|
||||||
|
|
||||||
if($removeAll && !isset($_GET['urls']) && $start == 0 && file_exists("../cache")) {
|
if($removeAll && !isset($_GET['urls']) && $start == 0 && file_exists("../cache")) {
|
||||||
echo "Removing stale cache files... \n";
|
echo "Removing stale cache files... \n";
|
||||||
flush();
|
flush();
|
||||||
if (FilesystemPublisher::$domain_based_caching) {
|
|
||||||
|
if (Config::inst()->get('FilesystemPublisher', 'domain_based_caching')) {
|
||||||
// Glob each dir, then glob each one of those
|
// Glob each dir, then glob each one of those
|
||||||
foreach(glob(BASE_PATH . '/cache/*', GLOB_ONLYDIR) as $cacheDir) {
|
foreach(glob(BASE_PATH . '/cache/*', GLOB_ONLYDIR) as $cacheDir) {
|
||||||
foreach(glob($cacheDir.'/*') as $cacheFile) {
|
foreach(glob($cacheDir.'/*') as $cacheFile) {
|
||||||
@ -88,16 +97,18 @@ class RebuildStaticCacheTask extends BuildTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "done.\n\n";
|
echo "done.\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Rebuilding cache from " . sizeof($mappedUrls) . " urls...\n\n";
|
echo "Rebuilding cache from " . sizeof($mappedUrls) . " urls...\n\n";
|
||||||
|
|
||||||
$page->extend('publishPages', $mappedUrls);
|
$page->extend('publishPages', $mappedUrls);
|
||||||
|
|
||||||
if (file_exists($cacheBaseDir.'/lock')) unlink($cacheBaseDir.'/lock');
|
if (file_exists($cacheBaseDir.'/lock')) {
|
||||||
|
unlink($cacheBaseDir.'/lock');
|
||||||
|
}
|
||||||
|
|
||||||
echo "\n\n== Done! ==";
|
echo "\n\n== Done! ==";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user