From dd84574b8da528e87582297aad6179ec88488ec4 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 14 Apr 2012 17:00:22 +1200 Subject: [PATCH] BUGFIX: upgrade module to fit 3.0 api. --- README.md | 3 +- _config.php | 4 ++- code/DocumentationSearch.php | 44 +++++++++++------------ code/DocumentationService.php | 4 +-- code/controllers/DocumentationViewer.php | 45 ++++++++++++------------ code/models/DocumentationPage.php | 17 ++++----- tests/DocumentationPageTest.php | 8 ++--- tests/DocumentationViewerTest.php | 1 - 8 files changed, 63 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 6912aef..ea5d1c9 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Requirements -* SilverStripe 2.4 +* SilverStripe 3.0 ## Summary @@ -20,4 +20,3 @@ For more documentation on how to use the module please read /docs/Writing-Docume (or via this in /dev/docs/sapphiredocs/Writing-Documentation in your webbrowser) **Note** This module assumes you are using numeric values for your versions. - diff --git a/_config.php b/_config.php index 9d17971..75e153d 100755 --- a/_config.php +++ b/_config.php @@ -11,7 +11,9 @@ if(!defined('DOCSVIEWER_PATH')) { } if(!defined('DOCSVIEWER_DIR')) { - define('DOCSVIEWER_DIR', array_pop(explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH))); + $dir = explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH); + + define('DOCSVIEWER_DIR', array_pop($dir)); } diff --git a/code/DocumentationSearch.php b/code/DocumentationSearch.php index ba64d7a..d934e7a 100755 --- a/code/DocumentationSearch.php +++ b/code/DocumentationSearch.php @@ -44,7 +44,7 @@ class DocumentationSearch { static $boost_by_path = array(); /** - * @var DataObjectSet - Results + * @var ArrayList - Results */ private $results; @@ -117,13 +117,13 @@ class DocumentationSearch { /** * Generate an array of every single documentation page installed on the system. * - * @return DataObjectSet + * @return ArrayList */ public static function get_all_documentation_pages() { DocumentationService::load_automatic_registration(); $modules = DocumentationService::get_registered_entities(); - $output = new DataObjectSet(); + $output = new ArrayList(); if($modules) { foreach($modules as $module) { @@ -245,8 +245,8 @@ class DocumentationSearch { $data = array( 'Results' => null, 'Query' => null, - 'Versions' => DBField::create('Text', implode(',', $this->versions)), - 'Modules' => DBField::create('Text', implode(',', $this->modules)), + 'Versions' => DBField::create_field('Text', implode(',', $this->versions)), + 'Modules' => DBField::create_field('Text', implode(',', $this->modules)), 'Title' => _t('DocumentationSearch.SEARCHRESULTS', 'Search Results'), 'TotalResults' => null, 'TotalPages' => null, @@ -254,9 +254,9 @@ class DocumentationSearch { 'StartResult' => null, 'PageLength' => $pageLength, 'EndResult' => null, - 'PrevUrl' => DBField::create('Text', 'false'), - 'NextUrl' => DBField::create('Text', 'false'), - 'SearchPages' => new DataObjectSet() + 'PrevUrl' => DBField::create_field('Text', 'false'), + 'NextUrl' => DBField::create_field('Text', 'false'), + 'SearchPages' => new ArrayList() ); $start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0; @@ -269,7 +269,7 @@ class DocumentationSearch { if ($totalPages == 0) $totalPages = 1; if ($currentPage > $totalPages) $currentPage = $totalPages; - $results = new DataObjectSet(); + $results = new ArrayList(); if($this->results) { foreach($this->results as $k => $hit) { @@ -280,13 +280,13 @@ class DocumentationSearch { $content = $hit->content; $obj = new ArrayData(array( - 'Title' => DBField::create('Varchar', $doc->getFieldValue('Title')), - 'BreadcrumbTitle' => DBField::create('HTMLText', $doc->getFieldValue('BreadcrumbTitle')), - 'Link' => DBField::create('Varchar',$doc->getFieldValue('Link')), - 'Language' => DBField::create('Varchar',$doc->getFieldValue('Language')), - 'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')), - 'Entity' => DBField::create('Varchar', $doc->getFieldValue('Entity')), - 'Content' => DBField::create('HTMLText', $content), + 'Title' => DBField::create_field('Varchar', $doc->getFieldValue('Title')), + 'BreadcrumbTitle' => DBField::create_field('HTMLText', $doc->getFieldValue('BreadcrumbTitle')), + 'Link' => DBField::create_field('Varchar',$doc->getFieldValue('Link')), + 'Language' => DBField::create_field('Varchar',$doc->getFieldValue('Language')), + 'Version' => DBField::create_field('Varchar',$doc->getFieldValue('Version')), + 'Entity' => DBField::create_field('Varchar', $doc->getFieldValue('Entity')), + 'Content' => DBField::create_field('HTMLText', $content), 'Score' => $hit->score, 'Number' => $k + 1, 'ID' => md5($doc->getFieldValue('Link')) @@ -297,22 +297,22 @@ class DocumentationSearch { } $data['Results'] = $results; - $data['Query'] = DBField::create('Text', $query); - $data['TotalResults'] = DBField::create('Text', count($this->results)); - $data['TotalPages'] = DBField::create('Text', $totalPages); - $data['ThisPage'] = DBField::create('Text', $currentPage); + $data['Query'] = DBField::create_field('Text', $query); + $data['TotalResults'] = DBField::create_field('Text', count($this->results)); + $data['TotalPages'] = DBField::create_field('Text', $totalPages); + $data['ThisPage'] = DBField::create_field('Text', $currentPage); $data['StartResult'] = $start + 1; $data['EndResult'] = $start + count($results); // Pagination links if($currentPage > 1) { - $data['PrevUrl'] = DBField::create('Text', + $data['PrevUrl'] = DBField::create_field('Text', $this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength)) ); } if($currentPage < $totalPages) { - $data['NextUrl'] = DBField::create('Text', + $data['NextUrl'] = DBField::create_field('Text', $this->buildQueryUrl(array('start' => $currentPage * $pageLength)) ); } diff --git a/code/DocumentationService.php b/code/DocumentationService.php index fdc8cc1..28078ad 100755 --- a/code/DocumentationService.php +++ b/code/DocumentationService.php @@ -455,10 +455,10 @@ class DocumentationService { * @param string - lang to use * * @throws Exception - * @return DataObjectSet + * @return ArrayList */ public static function get_pages_from_folder($entity, $relativePath = false, $recursive = true, $version = 'trunk', $lang = 'en') { - $output = new DataObjectSet(); + $output = new ArrayList(); $pages = array(); if(!$entity instanceof DocumentationEntity) diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index 0d06e3a..c23953d 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -76,7 +76,6 @@ class DocumentationViewer extends Controller { Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js'); Requirements::css(DOCSVIEWER_DIR .'/css/shSilverStripeDocs.css'); - Requirements::css(DOCSVIEWER_DIR .'/css/DocumentationViewer.css'); } @@ -128,7 +127,7 @@ class DocumentationViewer extends Controller { * * @return SS_HTTPResponse */ - public function handleRequest(SS_HTTPRequest $request) { + public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { // if we submitted a form, let that pass if(!$request->isGET() || isset($_GET['action_results'])) return parent::handleRequest($request); @@ -148,7 +147,7 @@ class DocumentationViewer extends Controller { if($firstParam) { // allow assets if($firstParam == "assets") { - return parent::handleRequest($request); + return parent::handleRequest($request, $model); } // check for permalinks @@ -199,7 +198,7 @@ class DocumentationViewer extends Controller { } - return parent::handleRequest($request); + return parent::handleRequest($request, $model); } return $this->throw404(); @@ -297,7 +296,7 @@ class DocumentationViewer extends Controller { * the filesystem then they are loaded under the 'Current' namespace. * * @param String $entity name of {@link Entity} to limit it to eg sapphire - * @return DataObjectSet + * @return ArrayList */ function getVersions($entity = false) { if(!$entity) $entity = $this->entity; @@ -306,7 +305,7 @@ class DocumentationViewer extends Controller { if(!$entity) return false; $versions = $entity->getVersions(); - $output = new DataObjectSet(); + $output = new ArrayList(); if($versions) { $lang = $this->getLang(); @@ -336,7 +335,7 @@ class DocumentationViewer extends Controller { */ function getEntities($version = false, $lang = false) { $entities = DocumentationService::get_registered_entities($version, $lang); - $output = new DataObjectSet(); + $output = new ArrayList(); $currentEntity = $this->getEntity(); @@ -349,7 +348,7 @@ class DocumentationViewer extends Controller { $content = false; if($page = $entity->getIndexPage($version, $lang)) { - $content = DBField::create('HTMLText', DocumentationParser::parse($page, $link)); + $content = DBField::create_field('HTMLText', DocumentationParser::parse($page, $link)); } $output->push(new ArrayData(array( @@ -457,7 +456,7 @@ class DocumentationViewer extends Controller { * * @todo this only handles 2 levels. Could make it recursive * - * @return false|DataObjectSet + * @return false|ArrayList */ function getEntityPages() { if($entity = $this->getEntity()) { @@ -493,7 +492,7 @@ class DocumentationViewer extends Controller { * @param DocumentationEntity * @param int Depth of page in the tree * - * @return DataObjectSet|false + * @return ArrayList|false */ private function _getEntityPagesNested(&$page, $entity, $level = 0) { if(isset($this->Remaining[$level])) { @@ -556,7 +555,7 @@ class DocumentationViewer extends Controller { $page = $this->getPage(); if($page) { - return DBField::create("HTMLText", $page->getHTML($this->getVersion(), $this->getLang())); + return DBField::create_field("HTMLText", $page->getHTML($this->getVersion(), $this->getLang())); } // If no page found then we may want to get the listing of the folder. @@ -594,14 +593,14 @@ class DocumentationViewer extends Controller { * Generate a list of breadcrumbs for the user. Based off the remaining params * in the url * - * @return DataObjectSet + * @return ArrayList */ function getBreadcrumbs() { if(!$this->Remaining) $this->Remaining = array(); $pages = array_merge(array($this->entity), $this->Remaining); - $output = new DataObjectSet(); + $output = new ArrayList(); if($pages) { $path = array(); @@ -690,7 +689,7 @@ class DocumentationViewer extends Controller { function LanguageForm() { $langs = $this->getLanguages(); - $fields = new FieldSet( + $fields = new FieldList( $dropdown = new DropdownField( 'LangCode', _t('DocumentationViewer.LANGUAGE', 'Language'), @@ -699,7 +698,7 @@ class DocumentationViewer extends Controller { ) ); - $actions = new FieldSet( + $actions = new FieldList( new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change')) ); @@ -749,13 +748,13 @@ class DocumentationViewer extends Controller { if(!DocumentationSearch::enabled()) return false; $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : ""; - $fields = new FieldSet( + $fields = new FieldList( new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q), new HiddenField('Entities', '', implode(',', array_keys($this->getSearchedEntities()))), new HiddenField('Versions', '', implode(',', $this->getSearchedVersions())) ); - $actions = new FieldSet( + $actions = new FieldList( new FormAction('results', 'Search') ); @@ -824,7 +823,7 @@ class DocumentationViewer extends Controller { */ function getSearchQuery() { if(isset($_REQUEST['Search'])) { - return DBField::create('HTMLText', $_REQUEST['Search']); + return DBField::create_field('HTMLText', $_REQUEST['Search']); } } @@ -867,7 +866,7 @@ class DocumentationViewer extends Controller { $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : ""; // klude to take an array of objects down to a simple map - $entities = new DataObjectSet($entities); + $entities = new ArrayList($entities); $entities = $entities->map('Folder', 'Title'); // if we haven't gone any search limit then we're searching everything @@ -877,7 +876,7 @@ class DocumentationViewer extends Controller { $searchedVersions = $this->getSearchedVersions(); if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions; - $fields = new FieldSet( + $fields = new FieldList( new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities), new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'), @@ -885,7 +884,7 @@ class DocumentationViewer extends Controller { ) ); - $actions = new FieldSet( + $actions = new FieldList( new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search')) ); $required = new RequiredFields(array('Search')); @@ -920,13 +919,13 @@ class DocumentationViewer extends Controller { if($version == "trunk" || $compare > 0) { return $this->customise(new ArrayData(array( 'FutureRelease' => true, - 'StableVersion' => DBField::create('HTMLText', $stable) + 'StableVersion' => DBField::create_field('HTMLText', $stable) ))); } else { return $this->customise(new ArrayData(array( 'OutdatedRelease' => true, - 'StableVersion' => DBField::create('HTMLText', $stable) + 'StableVersion' => DBField::create_field('HTMLText', $stable) ))); } } diff --git a/code/models/DocumentationPage.php b/code/models/DocumentationPage.php index 0af47f2..6e8f3e6 100755 --- a/code/models/DocumentationPage.php +++ b/code/models/DocumentationPage.php @@ -113,8 +113,9 @@ class DocumentationPage extends ViewableData { } /** - * @param String - has to be plain text for open search compatibility. - * @return String + * @param string - has to be plain text for open search compatibility. + * + * @return string */ function getBreadcrumbTitle($divider = ' - ') { $pathParts = explode('/', $this->getRelativePath()); @@ -128,11 +129,11 @@ class DocumentationPage extends ViewableData { } /** - * Returns the link for the web browser + * Returns the public accessible link for this page. * * @return string */ - function Link() { + function getLink() { if($entity = $this->getEntity()) { $link = Controller::join_links($entity->Link($this->getVersion(), $this->lang), $this->getRelativeLink()); @@ -194,7 +195,7 @@ class DocumentationPage extends ViewableData { /** * Set a variable from the metadata field on this class * - * @param String key + * @param string key * @param mixed value */ public function setMetaData($key, $value) { @@ -231,7 +232,7 @@ class DocumentationPage extends ViewableData { $ext = $this->getExtension(); if(DocumentationService::is_valid_extension($ext)) { - return file_get_contents($path); + return file_get_contents($path); } } } @@ -243,9 +244,9 @@ class DocumentationPage extends ViewableData { /** * Parse a file (with a lang and a version). * - * @param String $baselink + * @param string $baselink * - * @return String + * @return string */ function getHTML($version, $lang = 'en') { return DocumentationParser::parse($this, $this->entity->getRelativeLink($version, $lang)); diff --git a/tests/DocumentationPageTest.php b/tests/DocumentationPageTest.php index c6ce565..cf4d02f 100755 --- a/tests/DocumentationPageTest.php +++ b/tests/DocumentationPageTest.php @@ -15,21 +15,21 @@ class DocumentationPageTest extends SapphireTest { $page->setEntity($entity); // single layer - $this->assertStringEndsWith('testmodule/en/test', $page->Link(), 'The page link should have no extension and have a language'); + $this->assertStringEndsWith('testmodule/en/test', $page->Link, 'The page link should have no extension and have a language'); $folder = new DocumentationPage(); $folder->setRelativePath('sort'); $folder->setEntity($entity); // folder, should have a trailing slash - $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link()); + $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link); // second $nested = new DocumentationPage(); $nested->setRelativePath('subfolder/subpage.md'); $nested->setEntity($entity); - $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link()); + $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link); // test with version. $entity = DocumentationService::register("versionlinks", DOCSVIEWER_PATH ."/tests/docs-v2.4/", '1'); @@ -40,7 +40,7 @@ class DocumentationPageTest extends SapphireTest { $page->setRelativePath('test.md'); $page->setEntity($entity); $page->setVersion('1'); - $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link()); + $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link); } diff --git a/tests/DocumentationViewerTest.php b/tests/DocumentationViewerTest.php index 6f05f12..94119f5 100755 --- a/tests/DocumentationViewerTest.php +++ b/tests/DocumentationViewerTest.php @@ -133,7 +133,6 @@ class DocumentationViewerTest extends FunctionalTest { } $links = $pages->column('Link'); - $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/sort/', $links[0]); $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/', $links[1]); $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/test', $links[2]);