Closed UndefinedOffset closed 8 years ago
This will pose a challenge for the travis tests since we do want to include the cms there. Memory serves the travis support looks at the module requirements to handle what it should build the site out of. But there is the --require option that allows for additional composer requirements. So I think the following diff will work, but needs testing.
diff --git a/.travis.yml b/.travis.yml
index ff52d62..39c80bf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,7 +24,7 @@
before_script:
- phpenv rehash
- - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
+ - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support --require silverstripe/cms
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
diff --git a/code/control/KapostService.php b/code/control/KapostService.php
index 3302e31..1cf451c 100644
--- a/code/control/KapostService.php
+++ b/code/control/KapostService.php
@@ -305,7 +305,7 @@
if(array_key_exists('custom_fields', $content)) {
//Ensure the type is an extension of the KapostPage object
- if(!class_exists('Kapost'.$content['custom_fields']['kapost_custom_type']) || !('Kapost'.$content['custom_fields']['kapost_custom_type']=='KapostPage' || is_subclass_of('Kapost'.$content['custom_fields']['kapost_custom_type'], 'KapostPage'))) {
+ if(!class_exists('Kapost'.$content['custom_fields']['kapost_custom_type']) || !class_exists('SiteTree') || !('Kapost'.$content['custom_fields']['kapost_custom_type']=='KapostPage' || is_subclass_of('Kapost'.$content['custom_fields']['kapost_custom_type'], 'KapostPage'))) {
return $this->httpError(400, _t('KapostService.TYPE_NOT_KNOWN', '_The type "{type}" is not a known type', array('type'=>$content['custom_fields']['kapost_custom_type'])));
}
@@ -371,7 +371,7 @@
//Ensure the type is an extension of the KapostPage object
- if(array_key_exists('custom_fields', $content) && (!class_exists('Kapost'.$content['custom_fields']['kapost_custom_type']) || !('Kapost'.$content['custom_fields']['kapost_custom_type']=='KapostPage' || is_subclass_of('Kapost'.$content['custom_fields']['kapost_custom_type'], 'KapostPage')))) {
+ if(array_key_exists('custom_fields', $content) && (!class_exists('Kapost'.$content['custom_fields']['kapost_custom_type']) || !class_exists('SiteTree') || !('Kapost'.$content['custom_fields']['kapost_custom_type']=='KapostPage' || is_subclass_of('Kapost'.$content['custom_fields']['kapost_custom_type'], 'KapostPage')))) {
return $this->httpError(400, _t('KapostService.TYPE_NOT_KNOWN', '_The type "{type}" is not a known type', array('type'=>$content['custom_fields']['kapost_custom_type'])));
}
@@ -458,14 +458,19 @@
}
- //Switch Versioned to stage
- $oldReadingStage=Versioned::current_stage();
- Versioned::set_reading_mode('stage');
+ $page=null;
- $page=SiteTree::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
-
- //Switch Versioned back
- Versioned::set_reading_mode($oldReadingStage);
+ //If SiteTree exists attempt to lookup the record in the database
+ if(class_exists('SiteTree')) {
+ //Switch Versioned to stage
+ $oldReadingStage=Versioned::current_stage();
+ Versioned::set_reading_mode('Stage.stage');
+
+ $page=SiteTree::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
+
+ //Switch Versioned back
+ Versioned::set_reading_mode($oldReadingStage);
+ }
if(!empty($page) && $page!==false && $page->exists()) {
diff --git a/composer.json b/composer.json
index 83c2a7b..062e22a 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,6 @@
{
"php": ">=5.3.2",
"silverstripe/framework": "~3.1",
- "silverstripe/cms": "~3.1",
"phpxmlrpc/phpxmlrpc": "3.0.*",
"composer/installers": "*"
},
For the travis tests based on what the framework does to also test cms we could potentially do the following to .travis.yml. We'll also not want to apply the change above to .travis.yml.
diff --git a/.travis.yml b/.travis.yml
index 7001ffd..6859c0c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,11 +18,13 @@
- DB=MYSQL CORE_RELEASE=3.4
- DB=PGSQL CORE_RELEASE=3.4
- DB=SQLITE3 CORE_RELEASE=3.4
+ - DB=MYSQL CORE_RELEASE=3.4 CMS_TEST=1
before_script:
- phpenv rehash
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
+ - "if [ \"$CMS_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi"
+ - "if [ \"$CMS_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/cms:$CORE_RELEASE.x-dev; fi"
- cd ~/builds/ss
script:
Currently the module only supports cms and framework projects. I wonder if it is possible to strip it down to support framework only projects? Technically we could if SiteTree is not present we just don't handle KapostPage and require that extensions handle the response.