Merge branch '3.2' into 3.3

This commit is contained in:
Daniel Hensby 2016-08-23 10:55:13 +01:00
commit ba5e51c422
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 18 additions and 40 deletions

View File

@ -38,43 +38,38 @@ class OldPageRedirector extends Extension {
* Attempt to find an old/renamed page from some given the URL as an array
*
* @param array $params The array of URL, e.g. /foo/bar as array('foo', 'bar')
* @param SiteTree $parent The current parent in the recursive flow
* @param SiteTree|null $parent The current parent in the recursive flow
* @param boolean $redirect Whether we've found an old page worthy of a redirect
*
* @return string|boolean False, or the new URL
*/
static public function find_old_page($params, $parent = null, $redirect = false) {
$parent = is_numeric($parent) ? SiteTree::get()->byId($parent) : $parent;
$parent = is_numeric($parent) ? SiteTree::get()->byID($parent) : $parent;
$params = (array)$params;
$URL = rawurlencode(array_shift($params));
if (empty($URL)) { return false; }
$pages = SiteTree::get()->filter(array(
'URLSegment' => $URL,
));
if ($parent) {
$page = SiteTree::get()->filter(array('ParentID' => $parent->ID, 'URLSegment' => $URL))->First();
} else {
$page = SiteTree::get()->filter(array('URLSegment' => $URL))->First();
$pages = $pages->filter(array(
'ParentID' => $parent->ID,
));
}
$page = $pages->first();
if (!$page) {
// If we haven't found a candidate, lets resort to finding an old page with this URL segment
$oldFilter = array(
'"SiteTree_versions"."URLSegment"' => $URL,
'"SiteTree_versions"."WasPublished"' => true
);
if($parent) {
$oldFilter[] = array('"SiteTree_versions"."ParentID"' => $parent->ID);
}
$query = new SQLSelect(
'"RecordID"',
'"SiteTree_versions"',
$oldFilter,
'"LastEdited" DESC',
null,
null,
1
);
$record = $query->execute()->first();
$pages = $pages
->filter(array(
'WasPublished' => true,
))
->sort('LastEdited', 'DESC')
->setDataQueryParam("Versioned.mode", 'all_versions');
$record = $pages->first();
if ($record) {
$page = SiteTree::get()->byID($record['RecordID']);
$page = SiteTree::get()->byID($record->RecordID);
$redirect = true;
}
}

View File

@ -11,8 +11,6 @@ class ModelAsControllerTest extends FunctionalTest {
protected $autoFollowRedirection = false;
protected $orig = array();
/**
* New tests require nested urls to be enabled, but the site might not
* support nested URLs.
@ -22,24 +20,9 @@ class ModelAsControllerTest extends FunctionalTest {
public function setUp() {
parent::setUp();
$this->orig['nested_urls'] = SiteTree::config()->nested_urls;
Config::inst()->update('SiteTree', 'nested_urls', true);
}
/**
* New tests require nested urls to be enabled, but the site might not
* support nested URLs.
* This setup will enable nested-urls for this test and resets the state
* after the tests have been performed.
*/
public function tearDown() {
if (isset($this->orig['nested_urls']) && !$this->orig['nested_urls']) {
SiteTree::config()->nested_urls = false;
}
parent::tearDown();
}
protected function generateNestedPagesFixture() {
$level1 = new Page();