Merge pull request #109 from kinglozzer/4-compat

SilverStripe 4 compatibility
This commit is contained in:
Will Rossiter 2016-11-05 19:02:26 +13:00 committed by GitHub
commit 51fa6f4c25
11 changed files with 112 additions and 88 deletions

View File

@ -5,33 +5,23 @@ sudo: false
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
env:
- DB=MYSQL CORE_RELEASE=3.2
- DB=MYSQL CORE_RELEASE=master
matrix:
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.2
allow_failures:
- php: 7.0
env: DB=PGSQL CORE_RELEASE=master
before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- composer install
- composer require wilr/silverstripe-googlesitemaps
script:
- vendor/bin/phpunit googlesitemaps/tests

View File

@ -1,11 +0,0 @@
<?php
// add the extension to pages
if (class_exists('SiteTree')) {
SiteTree::add_extension('GoogleSitemapSiteTreeExtension');
}
// if you need to add this to DataObjects include the following in
// your own _config:
// GoogleSiteMap::register_dataobject('MyDataObject');

View File

@ -6,3 +6,10 @@ GoogleSitemap:
objects_per_sitemap: 1000
google_notification_enabled: false
use_show_in_search: true
---
Only:
classexists: SilverStripe\CMS\Model\SiteTree
---
SilverStripe\CMS\Model\SiteTree:
extensions:
- GoogleSitemapSiteTreeExtension

View File

@ -1,6 +1,6 @@
---
Name: googlesitemaproutes
---
Director:
SilverStripe\Control\Director:
rules:
'sitemap.xml': 'GoogleSitemapController'

View File

@ -1,4 +1,15 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Object;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\View\ArrayData;
/**
* Sitemaps are a way to tell Google about pages on your site that they might
* not otherwise discover. In its simplest terms, a XML Sitemap usually called
@ -225,8 +236,8 @@ class GoogleSitemap extends Object
Translatable::disable_locale_filter();
}
if ($class == "SiteTree") {
$instances = Versioned::get_by_stage('SiteTree', 'Live');
if ($class == SiteTree::class) {
$instances = Versioned::get_by_stage(SiteTree::class, 'Live');
if($filter) {
$instances = $instances->filter('ShowInSearch', 1);
@ -341,7 +352,7 @@ class GoogleSitemap extends Object
$sitemaps = new ArrayList();
$filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search');
if (class_exists('SiteTree')) {
if (class_exists(SiteTree::class)) {
// move to extension hook. At the moment moduleexists config hook
// does not work.
if (class_exists('Translatable')) {
@ -349,7 +360,7 @@ class GoogleSitemap extends Object
}
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
$class = 'SiteTree';
$class = SiteTree::class;
$instances = Versioned::get_by_stage($class, 'Live', $filter);
$this->extend("alterDataList", $instances, $class);
$count = $instances->count();
@ -365,7 +376,7 @@ class GoogleSitemap extends Object
$lastModified = ($lastEdited) ? date('Y-m-d', strtotime($lastEdited)) : date('Y-m-d');
$sitemaps->push(new ArrayData(array(
'ClassName' => 'SiteTree',
'ClassName' => $this->sanitiseClassName(SiteTree::class),
'LastModified' => $lastModified,
'Page' => $i
)));

View File

@ -1,5 +1,10 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\HTTPResponse;
/**
* Controller for displaying the sitemap.xml. The module displays an index
* sitemap at the sitemap.xml level, then outputs the individual objects
@ -45,7 +50,7 @@ class GoogleSitemapController extends Controller
'Sitemaps' => $sitemaps
);
} else {
return new SS_HTTPResponse('Page not found', 404);
return new HTTPResponse('Page not found', 404);
}
}
@ -60,7 +65,7 @@ class GoogleSitemapController extends Controller
$class = $this->unsanitiseClassName($this->request->param('ID'));
$page = $this->request->param('OtherID');
if (GoogleSitemap::enabled() && $class && $page && ($class == 'SiteTree' || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))) {
if (GoogleSitemap::enabled() && $class && $page && ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))) {
Config::inst()->update('SSViewer', 'set_source_file_comments', false);
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
@ -73,7 +78,7 @@ class GoogleSitemapController extends Controller
'Items' => $items
);
} else {
return new SS_HTTPResponse('Page not found', 404);
return new HTTPResponse('Page not found', 404);
}
}

View File

@ -1,5 +1,9 @@
<?php
use SilverStripe\Control\Director;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\FieldType\DBDatetime;
/**
* Decorate the page object to provide google sitemaps with
* additionally options and configuration.
@ -86,7 +90,7 @@ class GoogleSitemapExtension extends DataExtension
*
* @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic
*
* @return SS_Datetime
* @return DBDatetime
*/
public function getChangeFrequency()
{
@ -96,10 +100,10 @@ class GoogleSitemapExtension extends DataExtension
$date = date('Y-m-d H:i:s');
$created = new SS_Datetime();
$created = new DBDatetime();
$created->value = ($this->owner->Created) ? $this->owner->Created : $date;
$now = new SS_Datetime();
$now = new DBDatetime();
$now->value = $date;
$versions = ($this->owner->Version) ? $this->owner->Version : 1;

View File

@ -1,5 +1,10 @@
<?php
use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab;
/**
* @package googlesitemaps
*/

View File

@ -1,5 +1,17 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Versioning\Versioned;
/**
* TODO: Migrate to new instance level interface instead of using static methods for retrieval of site maps and items (i.e. ->getSitemaps() instead of ::get_sitemaps()).
*
@ -234,7 +246,7 @@ class GoogleSitemapTest extends FunctionalTest
$this->assertDOSContains(array(
array('Title' => 'Testpage1'),
array('Title' => 'Testpage2')
), GoogleSitemap::get_items('SiteTree'), "There should be 2 pages in the sitemap after publishing");
), GoogleSitemap::get_items(SiteTree::class), "There should be 2 pages in the sitemap after publishing");
// check if we make a page readonly that it is hidden
$page2->CanViewType = 'LoggedInUsers';
@ -245,7 +257,7 @@ class GoogleSitemapTest extends FunctionalTest
$this->assertDOSEquals(array(
array('Title' => 'Testpage1')
), GoogleSitemap::get_items('SiteTree'), "There should be only 1 page, other is logged in only");
), GoogleSitemap::get_items(SiteTree::class), "There should be only 1 page, other is logged in only");
}
public function testAccess()
@ -283,9 +295,9 @@ class GoogleSitemapTest extends FunctionalTest
$fields = $page->getSettingsFields();
$tab = $fields->fieldByName('Root')->fieldByName('Settings')->fieldByName('GoogleSitemap');
$this->assertInstanceOf('Tab', $tab);
$this->assertInstanceOf('DropdownField', $tab->fieldByName('Priority'));
$this->assertInstanceOf('LiteralField', $tab->fieldByName('GoogleSitemapIntro'));
$this->assertInstanceOf(Tab::class, $tab);
$this->assertInstanceOf(DropdownField::class, $tab->fieldByName('Priority'));
$this->assertInstanceOf(LiteralField::class, $tab->fieldByName('GoogleSitemapIntro'));
}
public function testGetPriority()
@ -311,7 +323,7 @@ class GoogleSitemapTest extends FunctionalTest
public function testUnpublishedPage()
{
if (!class_exists('SiteTree')) {
if (!class_exists(SiteTree::class)) {
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
}
@ -326,7 +338,7 @@ class GoogleSitemapTest extends FunctionalTest
$rootPage->publish("Stage", "Live");
$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Live');
Versioned::set_reading_mode('Live');
try {
$this->assertEmpty($orphanedPage->hasPublishedParent());
@ -349,7 +361,7 @@ class GoogleSitemapTest extends FunctionalTest
class GoogleSitemapTest_DataObject extends DataObject implements TestOnly
{
public static $db = array(
private static $db = array(
'Priority' => 'Varchar(10)'
);
@ -371,7 +383,7 @@ class GoogleSitemapTest_DataObject extends DataObject implements TestOnly
class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly
{
public static $db = array(
private static $db = array(
'Priority' => 'Varchar(10)'
);

View File

@ -2,7 +2,9 @@
namespace SilverStripe\GoogleSitemaps;
use Director, DataObject, TestOnly;
use SilverStripe\Control\Director;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
/**
* @package googlesitemaps
@ -10,7 +12,6 @@ use Director, DataObject, TestOnly;
*/
class Test_DataObject extends DataObject implements TestOnly
{
public static $db = array(
'Priority' => 'Varchar(10)'
);