Skip to content

Commit

Permalink
Merge pull request #44 from tractorcow/pulls/subsites-docid
Browse files Browse the repository at this point in the history
BUG Fix subsite document ID generation
  • Loading branch information
mateusz committed May 22, 2014
2 parents c39c4b4 + 23a1ba6 commit 12308ed
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details

language: php
language: php

php:
- 5.3

Expand All @@ -11,11 +12,16 @@ matrix:
include:
- php: 5.3
env: DB=PGSQL CORE_RELEASE=3.1
- php: 5.3
env: DB=MYSQL CORE_RELEASE=3.1 SUBSITES=1

before_script:
- composer self-update
- 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 [ \"$SUBSITES\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi"
- "if [ \"$SUBSITES\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/subsites; fi"
- cd ~/builds/ss

script:
- phpunit fulltextsearch/tests/
- vendor/bin/phpunit fulltextsearch/tests/
8 changes: 4 additions & 4 deletions code/search/SearchVariantSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function appliesTo($class, $includeSubclasses) {
}

function currentState() {
return Subsite::currentSubsiteID();
return (string)Subsite::currentSubsiteID();
}

function reindexStates() {
static $ids = null;

if ($ids === null) {
$ids = array(0);
foreach (DataObject::get('Subsite') as $subsite) $ids[] = $subsite->ID;
$ids = array('0');
foreach (DataObject::get('Subsite') as $subsite) $ids[] = (string)$subsite->ID;
}

return $ids;
Expand Down Expand Up @@ -77,7 +77,7 @@ function extractManipulationWriteState(&$writes) {

foreach ($write['statefulids'] as $i => $statefulid) {
foreach (self::$subsites as $subsiteID) {
$next[] = array('id' => $statefulid['id'], 'state' => array_merge($statefulid['state'], array($self => $subsiteID)));
$next[] = array('id' => $statefulid['id'], 'state' => array_merge($statefulid['state'], array($self => (string)$subsiteID)));
}
}

Expand Down
3 changes: 2 additions & 1 deletion docs/en/changelogs/1.0.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

Users upgrading from 1.0.2 or below will need to run the Solr_Reindex task to refresh
each SolrIndex. This is due to a change in record IDs, which are now generated from
the base class of each DataObject, rather than the instance class.
the base class of each DataObject, rather than the instance class, as well as fixes
to integration with the subsites module.

Developers working locally should be aware that by default, all indexes will be updated
in realtime when the environment is in dev mode, rather than attempting to queue these
Expand Down
17 changes: 11 additions & 6 deletions tests/SolrIndexVersionedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ protected function getServiceMock() {
return Phockito::mock('Solr3Service');
}

protected function getExpectedDocumentId($id, $stage) {
// Prevent subsites from breaking tests
$subsites = class_exists('Subsite') ? '"SearchVariantSubsites":"0",' : '';
return $id.'-SiteTree-{'.$subsites.'"SearchVariantVersioned":"'.$stage.'"}';
}

public function testPublishing() {

Expand All @@ -68,7 +73,7 @@ public function testPublishing() {
$item->write();
SearchUpdater::flush_dirty_indexes();
$doc = new SolrDocumentMatcher(array(
'_documentid' => $item->ID.'-SiteTree-{"SearchVariantVersioned":"Stage"}',
'_documentid' => $this->getExpectedDocumentId($item->ID, 'Stage'),
'ClassName' => 'SearchVariantVersionedTest_Item'
));
Phockito::verify($serviceMock)->addDocument($doc);
Expand All @@ -81,7 +86,7 @@ public function testPublishing() {
$item->publish('Stage', 'Live');
SearchUpdater::flush_dirty_indexes();
$doc = new SolrDocumentMatcher(array(
'_documentid' => $item->ID.'-SiteTree-{"SearchVariantVersioned":"Live"}',
'_documentid' => $this->getExpectedDocumentId($item->ID, 'Live'),
'ClassName' => 'SearchVariantVersionedTest_Item'
));
Phockito::verify($serviceMock)->addDocument($doc);
Expand All @@ -104,9 +109,9 @@ public function testDelete() {
$item->delete();
SearchUpdater::flush_dirty_indexes();
Phockito::verify($serviceMock, 1)
->deleteById($id.'-SiteTree-{"SearchVariantVersioned":"Live"}');
->deleteById($this->getExpectedDocumentId($id, 'Live'));
Phockito::verify($serviceMock, 0)
->deleteById($id.'-SiteTree-{"SearchVariantVersioned":"Stage"}');
->deleteById($this->getExpectedDocumentId($id, 'Stage'));

// Delete the stage record
Versioned::reading_stage('Stage');
Expand All @@ -118,9 +123,9 @@ public function testDelete() {
$item->delete();
SearchUpdater::flush_dirty_indexes();
Phockito::verify($serviceMock, 1)
->deleteById($id.'-SiteTree-{"SearchVariantVersioned":"Stage"}');
->deleteById($this->getExpectedDocumentId($id, 'Stage'));
Phockito::verify($serviceMock, 0)
->deleteById($id.'-SiteTree-{"SearchVariantVersioned":"Live"}');
->deleteById($this->getExpectedDocumentId($id, 'Live'));
}
}

Expand Down

0 comments on commit 12308ed

Please sign in to comment.