From 6e2906d01e6853341ebee3eb11c83632a86d7157 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 6 Apr 2013 17:26:15 +1300 Subject: [PATCH] API: remove static related classes, now staticpublisher module --- code/controllers/StaticExporter.php | 114 ------ code/staticpublisher/FilesystemPublisher.php | 371 ------------------ .../RsyncMultiHostPublisher.php | 73 ---- code/staticpublisher/StaticPublisher.php | 199 ---------- lang/af.yml | 4 - .../FilesystemPublisherTest.php | 184 --------- .../FilesystemPublisherTest.yml | 12 - 7 files changed, 957 deletions(-) delete mode 100644 code/controllers/StaticExporter.php delete mode 100644 code/staticpublisher/FilesystemPublisher.php delete mode 100644 code/staticpublisher/RsyncMultiHostPublisher.php delete mode 100644 code/staticpublisher/StaticPublisher.php delete mode 100644 tests/staticpublisher/FilesystemPublisherTest.php delete mode 100644 tests/staticpublisher/FilesystemPublisherTest.yml diff --git a/code/controllers/StaticExporter.php b/code/controllers/StaticExporter.php deleted file mode 100644 index 613f2e76..00000000 --- a/code/controllers/StaticExporter.php +++ /dev/null @@ -1,114 +0,0 @@ -Usage - * - * The exporter can only be invoked through a URL. Usage on commandline (through [sake](sake)) is not possible at the moment, as we're sending a file to the browser for download. - * - *
http://localhost/StaticExporter/export
- * - * Specify a custom baseurl in case you want to deploy the static HTML pages on a different host: - *
http://localhost/StaticExporter/export?baseurl=http://example.com
- * - * @see StaticPublisher - * - * @package cms - * @subpackage export - */ -class StaticExporter extends Controller { - - private static $allowed_actions = array( - 'index', - 'export', - ); - - public function init() { - parent::init(); - - $canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN")); - if(!$canAccess) return Security::permissionFailure($this); - } - - - public function Link($action = null) { - return "StaticExporter/$action"; - } - - public function index() { - echo "

"._t('StaticExporter.NAME','Static exporter')."

"; - echo $this->StaticExportForm()->forTemplate(); - } - - public function StaticExportForm() { - return new Form($this, 'StaticExportForm', new FieldList( - // new TextField('folder', _t('StaticExporter.FOLDEREXPORT','Folder to export to')), - new TextField('baseurl', _t('StaticExporter.BASEURL','Base URL')) - ), new FieldList( - new FormAction('export', _t('StaticExporter.EXPORTTO','Export to that folder')) - )); - } - - public function export() { - // specify custom baseurl for publishing to other webroot - if(isset($_REQUEST['baseurl'])) { - $base = $_REQUEST['baseurl']; - if(substr($base,-1) != '/') $base .= '/'; - Config::inst()->update('Director', 'alternate_base_url', $base); - } - - // setup temporary folders - $tmpBaseFolder = TEMP_FOLDER . '/static-export'; - $tmpFolder = (project()) ? "$tmpBaseFolder/" . project() : "$tmpBaseFolder/site"; - if(!file_exists($tmpFolder)) Filesystem::makeFolder($tmpFolder); - $baseFolderName = basename($tmpFolder); - - // symlink /assets - $f1 = ASSETS_PATH; - $f2 = Director::baseFolder() . '/' . project(); - `cd $tmpFolder; ln -s $f1; ln -s $f2`; - - // iterate through all instances of SiteTree - $pages = DataObject::get("SiteTree"); - foreach($pages as $page) { - $subfolder = "$tmpFolder/" . trim($page->RelativeLink(null, true), '/'); - $contentfile = "$tmpFolder/" . trim($page->RelativeLink(null, true), '/') . '/index.html'; - - // Make the folder - if(!file_exists($subfolder)) { - Filesystem::makeFolder($subfolder); - } - - // Run the page - Requirements::clear(); - $link = Director::makeRelative($page->Link()); - $response = Director::test($link); - - // Write to file - if($fh = fopen($contentfile, 'w')) { - fwrite($fh, $response->getBody()); - fclose($fh); - } - } - - // copy homepage (URLSegment: "home") to webroot - copy("$tmpFolder/home/index.html", "$tmpFolder/index.html"); - - // archive all generated files - `cd $tmpBaseFolder; tar -czhf $baseFolderName.tar.gz $baseFolderName`; - $archiveContent = file_get_contents("$tmpBaseFolder/$baseFolderName.tar.gz"); - - // remove temporary files and folder - Filesystem::removeFolder($tmpBaseFolder); - - // return as download to the client - $response = SS_HTTPRequest::send_file($archiveContent, "$baseFolderName.tar.gz", 'application/x-tar-gz'); - echo $response->output(); - } - -} - diff --git a/code/staticpublisher/FilesystemPublisher.php b/code/staticpublisher/FilesystemPublisher.php deleted file mode 100644 index 9ae0952b..00000000 --- a/code/staticpublisher/FilesystemPublisher.php +++ /dev/null @@ -1,371 +0,0 @@ -pagesAffectedByUnpublishing() to return other URLS - * that should be de-cached if $page is unpublished. - * - * @see http://doc.silverstripe.com/doku.php?id=staticpublisher - * - * @package cms - * @subpackage publishers - */ -class FilesystemPublisher extends StaticPublisher { - - /** - * @var String - */ - protected $destFolder = 'cache'; - - /** - * @var String - */ - protected $fileExtension = 'html'; - - /** - * @config - * @var String - */ - private static $static_base_url = null; - - /** - * @config - * @var Boolean Use domain based cacheing (put cache files into a domain subfolder) - * This must be true if you are using this with the "subsites" module. - * Please note that this form of caching requires all URLs to be provided absolute - * (not relative to the webroot) via {@link SiteTree->AbsoluteLink()}. - */ - private static $domain_based_caching = false; - - /** - * Set a different base URL for the static copy of the site. - * This can be useful if you are running the CMS on a different domain from the website. - * - * @deprecated 3.2 Use the "FilesystemPublisher.static_base_url" config setting instead - */ - static public function set_static_base_url($url) { - Deprecation::notice('3.2', 'Use the "FilesystemPublisher.static_base_url" config setting instead'); - Config::inst()->update('FilesystemPublisher', 'static_base_url', $url); - } - - /** - * @param $destFolder The folder to save the cached site into. - * This needs to be set in framework/static-main.php as well through the {@link $cacheBaseDir} variable. - * @param $fileExtension The file extension to use, e.g 'html'. - * If omitted, then each page will be placed in its own directory, - * with the filename 'index.html'. If you set the extension to PHP, then a simple PHP script will - * be generated that can do appropriate cache & redirect header negotation. - */ - public function __construct($destFolder = 'cache', $fileExtension = null) { - // Remove trailing slash from folder - if(substr($destFolder, -1) == '/') $destFolder = substr($destFolder, 0, -1); - - $this->destFolder = $destFolder; - $this->fileExtension = $fileExtension; - - parent::__construct(); - } - - /** - * Transforms relative or absolute URLs to their static path equivalent. - * This needs to be the same logic that's used to look up these paths through - * framework/static-main.php. Does not include the {@link $destFolder} prefix. - * - * URL filtering will have already taken place for direct SiteTree links via SiteTree->generateURLSegment()). - * For all other links (e.g. custom controller actions), we assume that they're pre-sanitized - * to suit the filesystem needs, as its impossible to sanitize them without risking to break - * the underlying naming assumptions in URL routing (e.g. controller method names). - * - * Examples (without $domain_based_caching): - * - http://mysite.com/mywebroot/ => /index.html (assuming your webroot is in a subfolder) - * - http://mysite.com/about-us => /about-us.html - * - http://mysite.com/parent/child => /parent/child.html - * - * Examples (with $domain_based_caching): - * - http://mysite.com/mywebroot/ => /mysite.com/index.html (assuming your webroot is in a subfolder) - * - http://mysite.com/about-us => /mysite.com/about-us.html - * - http://myothersite.com/about-us => /myothersite.com/about-us.html - * - http://subdomain.mysite.com/parent/child => /subdomain.mysite.com/parent/child.html - * - * @param Array $urls Absolute or relative URLs - * @return Array Map of original URLs to filesystem paths (relative to {@link $destFolder}). - */ - public function urlsToPaths($urls) { - $mappedUrls = array(); - foreach($urls as $url) { - - // parse_url() is not multibyte safe, see https://bugs.php.net/bug.php?id=52923. - // We assume that the URL hsa been correctly encoded either on storage (for SiteTree->URLSegment), - // or through URL collection (for controller method names etc.). - $urlParts = @parse_url($url); - - // Remove base folders from the URL if webroot is hosted in a subfolder (same as static-main.php) - $path = isset($urlParts['path']) ? $urlParts['path'] : ''; - if(mb_substr(mb_strtolower($path), 0, mb_strlen(BASE_URL)) == mb_strtolower(BASE_URL)) { - $urlSegment = mb_substr($path, mb_strlen(BASE_URL)); - } else { - $urlSegment = $path; - } - - // Normalize URLs - $urlSegment = trim($urlSegment, '/'); - - $filename = $urlSegment ? "$urlSegment.$this->fileExtension" : "index.$this->fileExtension"; - - if (Config::inst()->get('FilesystemPublisher', 'domain_based_caching')) { - if (!$urlParts) continue; // seriously malformed url here... - $filename = $urlParts['host'] . '/' . $filename; - } - - $mappedUrls[$url] = ((dirname($filename) == '/') ? '' : (dirname($filename).'/')).basename($filename); - } - - return $mappedUrls; - } - - public function unpublishPages($urls) { - // Do we need to map these? - // Detect a numerically indexed arrays - if (is_numeric(join('', array_keys($urls)))) $urls = $this->urlsToPaths($urls); - - // This can be quite memory hungry and time-consuming - // @todo - Make a more memory efficient publisher - increase_time_limit_to(); - increase_memory_limit_to(); - - $cacheBaseDir = $this->getDestDir(); - - foreach($urls as $url => $path) { - if (file_exists($cacheBaseDir.'/'.$path)) { - @unlink($cacheBaseDir.'/'.$path); - } - } - } - - /** - * Uses {@link Director::test()} to perform in-memory HTTP requests - * on the passed-in URLs. - * - * @param array $urls Relative URLs - * @return array Result, keyed by URL. Keys: - * - "statuscode": The HTTP status code - * - "redirect": A redirect location (if applicable) - * - "path": The filesystem path where the cache has been written - */ - public function publishPages($urls) { - $result = array(); - - // Do we need to map these? - // Detect a numerically indexed arrays - if (is_numeric(join('', array_keys($urls)))) $urls = $this->urlsToPaths($urls); - - // This can be quite memory hungry and time-consuming - // @todo - Make a more memory efficient publisher - increase_time_limit_to(); - increase_memory_limit_to(); - - // Set the appropriate theme for this publication batch. - // This may have been set explicitly via StaticPublisher::static_publisher_theme, - // or we can use the last non-null theme. - $customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme'); - if(!$customTheme) - Config::inst()->update('SSViewer', 'theme', Config::inst()->get('SSViewer', 'custom_theme')); - else - Config::inst()->update('SSViewer', 'theme', $customTheme); - - $currentBaseURL = Director::baseURL(); - $staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url'); - if($staticBaseUrl) Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl); - if($this->fileExtension == 'php') { - Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php'); - } - if(Config::inst()->get('StaticPublisher', 'echo_progress')) { - echo $this->class.": Publishing to " . $staticBaseUrl . "\n"; - } - $files = array(); - $i = 0; - $totalURLs = sizeof($urls); - foreach($urls as $url => $path) { - $origUrl = $url; - $result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null); - - if($staticBaseUrl) Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl); - $i++; - - if($url && !is_string($url)) { - user_error("Bad url:" . var_export($url,true), E_USER_WARNING); - continue; - } - - if(Config::inst()->get('StaticPublisher', 'echo_progress')) { - echo " * Publishing page $i/$totalURLs: $url\n"; - flush(); - } - - Requirements::clear(); - - if($url == "") $url = "/"; - if(Director::is_relative_url($url)) $url = Director::absoluteURL($url); - $response = Director::test(str_replace('+', ' ', $url)); - - if($response) { - $result[$origUrl]['statuscode'] = $response->getStatusCode(); - } - - Requirements::clear(); - - singleton('DataObject')->flushCache(); - - //skip any responses with a 404 status code. We don't want to turn those into statically cached pages - if (!$response || $response->getStatusCode() == '404') continue; - - // Generate file content - // PHP file caching will generate a simple script from a template - if($this->fileExtension == 'php') { - if(is_object($response)) { - if($response->getStatusCode() == '301' || $response->getStatusCode() == '302') { - $content = $this->generatePHPCacheRedirection($response->getHeader('Location')); - } else { - $content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s')); - } - } else { - $content = $this->generatePHPCacheFile($response . '', HTTP::get_cache_age(), date('Y-m-d H:i:s')); - } - - // HTML file caching generally just creates a simple file - } else { - if(is_object($response)) { - if($response->getStatusCode() == '301' || $response->getStatusCode() == '302') { - $absoluteURL = Director::absoluteURL($response->getHeader('Location')); - $result[$origUrl]['redirect'] = $response->getHeader('Location'); - $content = ""; - } else { - $content = $response->getBody(); - } - } else { - $content = $response . ''; - } - } - - if(Config::inst()->get('StaticPublisher', 'include_caching_metadata')) { - $content = str_replace( - '', - sprintf("\n\n", implode(" ", $this->getMetadata($url))), - $content - ); - } - - $files[$origUrl] = array( - 'Content' => $content, - 'Folder' => dirname($path).'/', - 'Filename' => basename($path), - ); - - // Add externals - /* - $externals = $this->externalReferencesFor($content); - if($externals) foreach($externals as $external) { - // Skip absolute URLs - if(preg_match('/^[a-zA-Z]+:\/\//', $external)) continue; - // Drop querystring parameters - $external = strtok($external, '?'); - - if(file_exists("../" . $external)) { - // Break into folder and filename - if(preg_match('/^(.*\/)([^\/]+)$/', $external, $matches)) { - $files[$external] = array( - "Copy" => "../$external", - "Folder" => $matches[1], - "Filename" => $matches[2], - ); - - } else { - user_error("Can't parse external: $external", E_USER_WARNING); - } - } else { - $missingFiles[$external] = true; - } - }*/ - } - - if(Config::inst()->get('FilesystemPublisher', 'static_base_url')) Config::inst()->update('Director', 'alternate_base_url', $currentBaseURL); - if($this->fileExtension == 'php') { - Config::inst()->update('SSViewer', 'rewrite_hash_links', true); - } - - $base = BASE_PATH . "/$this->destFolder"; - foreach($files as $origUrl => $file) { - Filesystem::makeFolder("$base/$file[Folder]"); - - $path = "$base/$file[Folder]$file[Filename]"; - $result[$origUrl]['path'] = $path; - - if(isset($file['Content'])) { - $fh = fopen($path, "w"); - fwrite($fh, $file['Content']); - fclose($fh); - } else if(isset($file['Copy'])) { - copy($file['Copy'], $path); - } - } - - return $result; - } - - /** - * Generate the templated content for a PHP script that can serve up the given piece of content with the given age and expiry - */ - protected function generatePHPCacheFile($content, $age, $lastModified) { - $template = file_get_contents(BASE_PATH . '/cms/code/staticpublisher/CachedPHPPage.tmpl'); - return str_replace( - array('**MAX_AGE**', '**LAST_MODIFIED**', '**CONTENT**'), - array((int)$age, $lastModified, $content), - $template); - } - /** - * Generate the templated content for a PHP script that can serve up a 301 redirect to the given destionation - */ - protected function generatePHPCacheRedirection($destination) { - $template = file_get_contents(BASE_PATH . '/cms/code/staticpublisher/CachedPHPRedirection.tmpl'); - return str_replace( - array('**DESTINATION**'), - array($destination), - $template); - } - - public function getDestDir() { - return BASE_PATH . '/' . $this->destFolder; - } - - /** - * Return an array of all the existing static cache files, as a map of URL => file. - * Only returns cache files that will actually map to a URL, based on urlsToPaths. - */ - public function getExistingStaticCacheFiles() { - $cacheDir = BASE_PATH . '/' . $this->destFolder; - - $urlMapper = array_flip($this->urlsToPaths($this->owner->allPagesToCache())); - - $output = array(); - - // Glob each dir, then glob each one of those - foreach(glob("$cacheDir/*", GLOB_ONLYDIR) as $cacheDir) { - foreach(glob($cacheDir.'/*') as $cacheFile) { - $mapKey = str_replace(BASE_PATH . "/cache/","",$cacheFile); - if(isset($urlMapper[$mapKey])) { - $url = $urlMapper[$mapKey]; - $output[$url] = $cacheFile; - } - } - } - - return $output; - } - -} - diff --git a/code/staticpublisher/RsyncMultiHostPublisher.php b/code/staticpublisher/RsyncMultiHostPublisher.php deleted file mode 100644 index 0ca03f6b..00000000 --- a/code/staticpublisher/RsyncMultiHostPublisher.php +++ /dev/null @@ -1,73 +0,0 @@ -update('RsyncMultiHostPublisher', 'targets', $targets); - } - - /** - * Specify folders to exclude from the rsync - * For example, you could exclude assets. - * - * @deprecated 3.2 Use the "RsyncMultiHostPublisher.excluded_folders" config setting instead - */ - static public function set_excluded_folders($folders) { - Deprecation::notice('3.2', 'Use the "RsyncMultiHostPublisher.excluded_folders" config setting instead'); - Config::inst()->update('RsyncMultiHostPublisher', 'excluded_folders', $folders); - } - - public function publishPages($urls) { - parent::publishPages($urls); - $base = Director::baseFolder(); - $framework = FRAMEWORK_DIR; - - // Get variable that can turn off the rsync component of publication - if(isset($_GET['norsync']) && $_GET['norsync']) return; - - $extraArg = ""; - if($this->config()->excluded_folders) foreach($this->config()->excluded_folders as $folder) { - $extraArg .= " --exclude " . escapeshellarg($folder); - } - - foreach((array)$this->config()->targets as $target) { - // Transfer non-PHP content from everything to the target; that will ensure that we have all the JS/CSS/etc - $rsyncOutput = `cd $base; rsync -av -e ssh --exclude /.htaccess --exclude /web.config --exclude '*.php' --exclude '*.svn' --exclude '*.git' --exclude '*~' $extraArg --delete . $target`; - // Then transfer "safe" PHP from the cache/ directory - $rsyncOutput .= `cd $base; rsync -av -e ssh --exclude '*.svn' --exclude '*~' $extraArg --delete cache $target`; - // Transfer framework/static-main.php to the target - $rsyncOutput .= `cd $base; rsync -av -e ssh --delete $framework/static-main.php $target/$framework`; - if(Config::inst()->get('StaticPublisher', 'echo_progress')) echo $rsyncOutput; - } - } - -} diff --git a/code/staticpublisher/StaticPublisher.php b/code/staticpublisher/StaticPublisher.php deleted file mode 100644 index 095053db..00000000 --- a/code/staticpublisher/StaticPublisher.php +++ /dev/null @@ -1,199 +0,0 @@ -update('SSViewer', 'theme', ) is used - * The obvious place to set this is in _config.php - */ - private static $static_publisher_theme=false; - - abstract public function publishPages($pages); - abstract public function unpublishPages($pages); - - /** - * @deprecated 3.2 Use the "StaticPublisher.static_publisher_theme" config setting instead - * @param [type] $theme [description] - */ - static public function set_static_publisher_theme($theme){ - Deprecation::notice('3.2', 'Use the "StaticPublisher.static_publisher_theme" config setting instead'); - Config::inst()->update('StaticPublisher', 'static_publisher_theme', $theme); - } - - /** - * @config - * @var boolean Includes a timestamp at the bottom of the generated HTML of each file, - * which can be useful for debugging issues with stale caches etc. - */ - private static $include_caching_metadata = false; - - /** - * @deprecated 3.2 Use the "StaticPublisher.static_publisher_theme" config setting instead - */ - static public function static_publisher_theme(){ - Deprecation::notice('3.2', 'Use the "StaticPublisher.static_publisher_theme" config setting instead'); - return Config::inst()->get('StaticPublisher', 'static_publisher_theme'); - } - - /** - * @deprecated 3.2 Use the "StaticPublisher.echo_progress" config setting instead - */ - static public function echo_progress() { - Deprecation::notice('3.2', 'Use the "StaticPublisher.echo_progress" config setting instead'); - return Config::inst()->get('StaticPublisher', 'echo_progress'); - } - - /** - * Either turns on (boolean true) or off (boolean false) the progress indicators. - * @deprecated 3.2 Use the "StaticPublisher.echo_progress" config setting instead - * @see StaticPublisher::$echo_progress - */ - static public function set_echo_progress($progress) { - Deprecation::notice('3.2', 'Use the "StaticPublisher.echo_progress" config setting instead'); - Config::inst()->update('StaticPublisher', 'echo_progress', $progress); - } - - /** - * Called after a page is published. - */ - public function onAfterPublish($original) { - $this->republish($original); - } - - /** - * Called after link assets have been renamed, and the live site has been updated, without - * an actual publish event. - * - * Only called if the published content exists and has been modified. - */ - public function onRenameLinkedAsset($original) { - $this->republish($original); - } - - public function republish($original) { - if (Config::inst()->get('StaticPublisher', 'disable_realtime')) return; - - $urls = array(); - - if($this->owner->hasMethod('pagesAffectedByChanges')) { - $urls = $this->owner->pagesAffectedByChanges($original); - } else { - $pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10); - if($pages) { - foreach($pages as $page) { - $urls[] = $page->AbsoluteLink(); - } - } - } - - // Note: Similiar to RebuildStaticCacheTask->rebuildCache() - foreach($urls as $i => $url) { - if(!is_string($url)) { - user_error("Bad URL: " . var_export($url, true), E_USER_WARNING); - 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 = array_unique($urls); - - $this->publishPages($urls); - } - - /** - * On after unpublish, get changes and hook into underlying - * functionality - */ - public function onAfterUnpublish($page) { - if (Config::inst()->get('StaticPublisher', 'disable_realtime')) return; - - // Get the affected URLs - if($this->owner->hasMethod('pagesAffectedByUnpublishing')) { - $urls = $this->owner->pagesAffectedByUnpublishing(); - $urls = array_unique($urls); - } else { - $urls = array($this->owner->AbsoluteLink()); - } - - $legalPages = singleton('Page')->allPagesToCache(); - - $urlsToRepublish = array_intersect($urls, $legalPages); - $urlsToUnpublish = array_diff($urls, $legalPages); - - $this->unpublishPages($urlsToUnpublish); - $this->publishPages($urlsToRepublish); - } - - /** - * Get all external references to CSS, JS, - */ - public function externalReferencesFor($content) { - $CLI_content = escapeshellarg($content); - $tidy = `echo $CLI_content | tidy -numeric -asxhtml`; - $tidy = preg_replace('/xmlns="[^"]+"/','', $tidy); - $xContent = new SimpleXMLElement($tidy); - //Debug::message($xContent->asXML()); - - $xlinks = array( - "//link[@rel='stylesheet']/@href" => false, - "//script/@src" => false, - "//img/@src" => false, - "//a/@href" => true, - ); - - $urls = array(); - foreach($xlinks as $xlink => $assetsOnly) { - $matches = $xContent->xpath($xlink); - if($matches) foreach($matches as $item) { - $url = $item . ''; - if($assetsOnly && substr($url,0,7) != ASSETS_DIR . '/') continue; - - $urls[] = $url; - } - } - - return $urls; - } - - /** - * Provides context for this URL, written as an HTML comment to the static file cache, - * which can be useful for debugging cache problems. For example, you could track the - * event or related page which triggered this republication. The returned data - * is unstructured and not intended to be consumed programmatically. - * Consider injecting standard HTML tags instead where applicable. - * - * Note: Only used when {@link $include_caching_metadata} is enabled. - * - * @param String - * @return Array A numeric array of all metadata. - */ - function getMetadata($url) { - return array( - 'Cache generated on ' . date('Y-m-d H:i:s T (O)') - ); - } -} - diff --git a/lang/af.yml b/lang/af.yml index 28fbd630..45d5237e 100644 --- a/lang/af.yml +++ b/lang/af.yml @@ -377,10 +377,6 @@ af: many_many_LinkTracking: 'Link Tracking' SiteTreeURLSegmentField: HelpChars: ' Special characters are automatically converted or removed.' - StaticExporter: - BASEURL: 'Base URL' - EXPORTTO: 'Export to that folder' - NAME: 'Static exporter' TableListField: SELECT: 'Select:' TableListField.ss: diff --git a/tests/staticpublisher/FilesystemPublisherTest.php b/tests/staticpublisher/FilesystemPublisherTest.php deleted file mode 100644 index 26327f4c..00000000 --- a/tests/staticpublisher/FilesystemPublisherTest.php +++ /dev/null @@ -1,184 +0,0 @@ -update('FilesystemPublisher', 'domain_based_caching', false); - } - - public function tearDown() { - parent::tearDown(); - - SiteTree::remove_extension("FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')"); - - if(file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) { - Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder'); - } - } - - public function testUrlsToPathsWithRelativeUrls() { - $fsp = new FilesystemPublisher('.', 'html'); - - $this->assertEquals( - $fsp->urlsToPaths(array('/')), - array('/' => './index.html'), - 'Root URL path mapping' - ); - - $this->assertEquals( - $fsp->urlsToPaths(array('about-us')), - array('about-us' => './about-us.html'), - 'URLsegment path mapping' - ); - - $this->assertEquals( - $fsp->urlsToPaths(array('parent/child')), - array('parent/child' => 'parent/child.html'), - 'Nested URLsegment path mapping' - ); - } - - public function testUrlsToPathsWithAbsoluteUrls() { - $fsp = new FilesystemPublisher('.', 'html'); - - $url = Director::absoluteBaseUrl(); - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => './index.html'), - 'Root URL path mapping' - ); - - $url = Director::absoluteBaseUrl() . 'about-us'; - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => './about-us.html'), - 'URLsegment path mapping' - ); - - $url = Director::absoluteBaseUrl() . 'parent/child'; - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => 'parent/child.html'), - 'Nested URLsegment path mapping' - ); - } - - public function testUrlsToPathsWithDomainBasedCaching() { - Config::inst()->update('FilesystemPublisher', 'domain_based_caching', true); - - $fsp = new FilesystemPublisher('.', 'html'); - - $url = 'http://domain1.com/'; - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => 'domain1.com/index.html'), - 'Root URL path mapping' - ); - - $url = 'http://domain1.com/about-us'; - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => 'domain1.com/about-us.html'), - 'URLsegment path mapping' - ); - - $url = 'http://domain2.com/parent/child'; - $this->assertEquals( - $fsp->urlsToPaths(array($url)), - array($url => 'domain2.com/parent/child.html'), - 'Nested URLsegment path mapping' - ); - } - - /** - * Simple test to ensure that FileSystemPublisher::__construct() - * has called parent::__construct() by checking the class property. - * The class property is set on {@link Object::__construct()} and - * this is therefore a good test to ensure it was called. - * - * If FilesystemPublisher doesn't call parent::__construct() then - * it won't be enabled propery because {@link Object::__construct()} - * is where extension instances are set up and subsequently used by - * {@link DataObject::defineMethods()}. - */ - public function testHasCalledParentConstructor() { - $fsp = new FilesystemPublisher('.', '.html'); - $this->assertEquals($fsp->class, 'FilesystemPublisher'); - } - - /* - * These are a few simple tests to check that we will be retrieving the correct theme when we need it - * StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called. - */ - public function testStaticPublisherTheme(){ - - //This will be the name of the default theme of this particular project - $default_theme= Config::inst()->get('SSViewer', 'theme'); - - $p1 = new Page(); - $p1->URLSegment = strtolower(__CLASS__).'-page-1'; - $p1->HomepageForDomain = ''; - $p1->write(); - $p1->doPublish(); - - $current_theme=Config::inst()->get('SSViewer', 'custom_theme'); - $this->assertEquals($current_theme, $default_theme, 'After a standard publication, the theme is correct'); - - //The CMS sometimes sets the theme to null. Check that the $current_custom_theme is still the default - Config::inst()->update('SSViewer', 'theme', null); - $current_theme=Config::inst()->get('SSViewer', 'custom_theme'); - $this->assertEquals($current_theme, $default_theme, 'After a setting the theme to null, the default theme is correct'); - } - - function testPublishPages() { - $cacheFolder = '/assets/FilesystemPublisherTest-static-folder/'; - $cachePath = Director::baseFolder() . $cacheFolder; - $publisher = new FilesystemPublisher($cacheFolder, 'html'); - $page1 = $this->objFromFixture('Page', 'page1'); - $page1->publish('Stage', 'Live'); - $redirector1 = $this->objFromFixture('RedirectorPage', 'redirector1'); - $redirector1->publish('Stage', 'Live'); - - $results = $publisher->publishPages(array( - $page1->Link(), - $redirector1->regularLink(), - '/notfound' - )); - - $this->assertArrayHasKey($page1->Link(), $results); - $this->assertEquals(200, $results[$page1->Link()]['statuscode']); - $this->assertEquals( - realpath($results[$page1->Link()]['path']), - realpath($cachePath . './page1.html') - ); - - $this->assertArrayHasKey($redirector1->regularLink(), $results); - $this->assertEquals(301, $results[$redirector1->regularLink()]['statuscode']); - $this->assertEquals(Director::baseURL() . 'page1/', $results[$redirector1->regularLink()]['redirect']); - $this->assertEquals( - realpath($results[$redirector1->regularLink()]['path']), - realpath($cachePath . './redirect-to-page1.html') - ); - - $this->assertArrayHasKey('/notfound', $results); - $this->assertEquals(404, $results['/notfound']['statuscode']); - $this->assertNull($results['/notfound']['redirect']); - $this->assertNull($results['/notfound']['path']); - } - -} diff --git a/tests/staticpublisher/FilesystemPublisherTest.yml b/tests/staticpublisher/FilesystemPublisherTest.yml deleted file mode 100644 index ce4b87cc..00000000 --- a/tests/staticpublisher/FilesystemPublisherTest.yml +++ /dev/null @@ -1,12 +0,0 @@ -Page: - page1: - URLSegment: page1 - page1a: - URLSegment: page1a - Parent: =>Page.page1 - page2: - URLSegment: page2 -RedirectorPage: - redirector1: - URLSegment: redirect-to-page1 - LinkTo: =>Page.page1 \ No newline at end of file