BUGFIX: upgrade module to fit 3.0 api.

This commit is contained in:
Will Rossiter 2012-04-14 17:00:22 +12:00
parent 1e28e8252f
commit dd84574b8d
8 changed files with 63 additions and 63 deletions

View File

@ -7,7 +7,7 @@
## Requirements ## Requirements
* SilverStripe 2.4 * SilverStripe 3.0
## Summary ## 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) (or via this in /dev/docs/sapphiredocs/Writing-Documentation in your webbrowser)
**Note** This module assumes you are using numeric values for your versions. **Note** This module assumes you are using numeric values for your versions.

View File

@ -11,7 +11,9 @@ if(!defined('DOCSVIEWER_PATH')) {
} }
if(!defined('DOCSVIEWER_DIR')) { 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));
} }

View File

@ -44,7 +44,7 @@ class DocumentationSearch {
static $boost_by_path = array(); static $boost_by_path = array();
/** /**
* @var DataObjectSet - Results * @var ArrayList - Results
*/ */
private $results; private $results;
@ -117,13 +117,13 @@ class DocumentationSearch {
/** /**
* Generate an array of every single documentation page installed on the system. * Generate an array of every single documentation page installed on the system.
* *
* @return DataObjectSet * @return ArrayList
*/ */
public static function get_all_documentation_pages() { public static function get_all_documentation_pages() {
DocumentationService::load_automatic_registration(); DocumentationService::load_automatic_registration();
$modules = DocumentationService::get_registered_entities(); $modules = DocumentationService::get_registered_entities();
$output = new DataObjectSet(); $output = new ArrayList();
if($modules) { if($modules) {
foreach($modules as $module) { foreach($modules as $module) {
@ -245,8 +245,8 @@ class DocumentationSearch {
$data = array( $data = array(
'Results' => null, 'Results' => null,
'Query' => null, 'Query' => null,
'Versions' => DBField::create('Text', implode(',', $this->versions)), 'Versions' => DBField::create_field('Text', implode(',', $this->versions)),
'Modules' => DBField::create('Text', implode(',', $this->modules)), 'Modules' => DBField::create_field('Text', implode(',', $this->modules)),
'Title' => _t('DocumentationSearch.SEARCHRESULTS', 'Search Results'), 'Title' => _t('DocumentationSearch.SEARCHRESULTS', 'Search Results'),
'TotalResults' => null, 'TotalResults' => null,
'TotalPages' => null, 'TotalPages' => null,
@ -254,9 +254,9 @@ class DocumentationSearch {
'StartResult' => null, 'StartResult' => null,
'PageLength' => $pageLength, 'PageLength' => $pageLength,
'EndResult' => null, 'EndResult' => null,
'PrevUrl' => DBField::create('Text', 'false'), 'PrevUrl' => DBField::create_field('Text', 'false'),
'NextUrl' => DBField::create('Text', 'false'), 'NextUrl' => DBField::create_field('Text', 'false'),
'SearchPages' => new DataObjectSet() 'SearchPages' => new ArrayList()
); );
$start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0; $start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0;
@ -269,7 +269,7 @@ class DocumentationSearch {
if ($totalPages == 0) $totalPages = 1; if ($totalPages == 0) $totalPages = 1;
if ($currentPage > $totalPages) $currentPage = $totalPages; if ($currentPage > $totalPages) $currentPage = $totalPages;
$results = new DataObjectSet(); $results = new ArrayList();
if($this->results) { if($this->results) {
foreach($this->results as $k => $hit) { foreach($this->results as $k => $hit) {
@ -280,13 +280,13 @@ class DocumentationSearch {
$content = $hit->content; $content = $hit->content;
$obj = new ArrayData(array( $obj = new ArrayData(array(
'Title' => DBField::create('Varchar', $doc->getFieldValue('Title')), 'Title' => DBField::create_field('Varchar', $doc->getFieldValue('Title')),
'BreadcrumbTitle' => DBField::create('HTMLText', $doc->getFieldValue('BreadcrumbTitle')), 'BreadcrumbTitle' => DBField::create_field('HTMLText', $doc->getFieldValue('BreadcrumbTitle')),
'Link' => DBField::create('Varchar',$doc->getFieldValue('Link')), 'Link' => DBField::create_field('Varchar',$doc->getFieldValue('Link')),
'Language' => DBField::create('Varchar',$doc->getFieldValue('Language')), 'Language' => DBField::create_field('Varchar',$doc->getFieldValue('Language')),
'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')), 'Version' => DBField::create_field('Varchar',$doc->getFieldValue('Version')),
'Entity' => DBField::create('Varchar', $doc->getFieldValue('Entity')), 'Entity' => DBField::create_field('Varchar', $doc->getFieldValue('Entity')),
'Content' => DBField::create('HTMLText', $content), 'Content' => DBField::create_field('HTMLText', $content),
'Score' => $hit->score, 'Score' => $hit->score,
'Number' => $k + 1, 'Number' => $k + 1,
'ID' => md5($doc->getFieldValue('Link')) 'ID' => md5($doc->getFieldValue('Link'))
@ -297,22 +297,22 @@ class DocumentationSearch {
} }
$data['Results'] = $results; $data['Results'] = $results;
$data['Query'] = DBField::create('Text', $query); $data['Query'] = DBField::create_field('Text', $query);
$data['TotalResults'] = DBField::create('Text', count($this->results)); $data['TotalResults'] = DBField::create_field('Text', count($this->results));
$data['TotalPages'] = DBField::create('Text', $totalPages); $data['TotalPages'] = DBField::create_field('Text', $totalPages);
$data['ThisPage'] = DBField::create('Text', $currentPage); $data['ThisPage'] = DBField::create_field('Text', $currentPage);
$data['StartResult'] = $start + 1; $data['StartResult'] = $start + 1;
$data['EndResult'] = $start + count($results); $data['EndResult'] = $start + count($results);
// Pagination links // Pagination links
if($currentPage > 1) { if($currentPage > 1) {
$data['PrevUrl'] = DBField::create('Text', $data['PrevUrl'] = DBField::create_field('Text',
$this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength)) $this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength))
); );
} }
if($currentPage < $totalPages) { if($currentPage < $totalPages) {
$data['NextUrl'] = DBField::create('Text', $data['NextUrl'] = DBField::create_field('Text',
$this->buildQueryUrl(array('start' => $currentPage * $pageLength)) $this->buildQueryUrl(array('start' => $currentPage * $pageLength))
); );
} }

View File

@ -455,10 +455,10 @@ class DocumentationService {
* @param string - lang to use * @param string - lang to use
* *
* @throws Exception * @throws Exception
* @return DataObjectSet * @return ArrayList
*/ */
public static function get_pages_from_folder($entity, $relativePath = false, $recursive = true, $version = 'trunk', $lang = 'en') { public static function get_pages_from_folder($entity, $relativePath = false, $recursive = true, $version = 'trunk', $lang = 'en') {
$output = new DataObjectSet(); $output = new ArrayList();
$pages = array(); $pages = array();
if(!$entity instanceof DocumentationEntity) if(!$entity instanceof DocumentationEntity)

View File

@ -76,7 +76,6 @@ class DocumentationViewer extends Controller {
Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js'); Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js');
Requirements::css(DOCSVIEWER_DIR .'/css/shSilverStripeDocs.css'); Requirements::css(DOCSVIEWER_DIR .'/css/shSilverStripeDocs.css');
Requirements::css(DOCSVIEWER_DIR .'/css/DocumentationViewer.css'); Requirements::css(DOCSVIEWER_DIR .'/css/DocumentationViewer.css');
} }
@ -128,7 +127,7 @@ class DocumentationViewer extends Controller {
* *
* @return SS_HTTPResponse * @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 we submitted a form, let that pass
if(!$request->isGET() || isset($_GET['action_results'])) if(!$request->isGET() || isset($_GET['action_results']))
return parent::handleRequest($request); return parent::handleRequest($request);
@ -148,7 +147,7 @@ class DocumentationViewer extends Controller {
if($firstParam) { if($firstParam) {
// allow assets // allow assets
if($firstParam == "assets") { if($firstParam == "assets") {
return parent::handleRequest($request); return parent::handleRequest($request, $model);
} }
// check for permalinks // check for permalinks
@ -199,7 +198,7 @@ class DocumentationViewer extends Controller {
} }
return parent::handleRequest($request); return parent::handleRequest($request, $model);
} }
return $this->throw404(); return $this->throw404();
@ -297,7 +296,7 @@ class DocumentationViewer extends Controller {
* the filesystem then they are loaded under the 'Current' namespace. * the filesystem then they are loaded under the 'Current' namespace.
* *
* @param String $entity name of {@link Entity} to limit it to eg sapphire * @param String $entity name of {@link Entity} to limit it to eg sapphire
* @return DataObjectSet * @return ArrayList
*/ */
function getVersions($entity = false) { function getVersions($entity = false) {
if(!$entity) $entity = $this->entity; if(!$entity) $entity = $this->entity;
@ -306,7 +305,7 @@ class DocumentationViewer extends Controller {
if(!$entity) return false; if(!$entity) return false;
$versions = $entity->getVersions(); $versions = $entity->getVersions();
$output = new DataObjectSet(); $output = new ArrayList();
if($versions) { if($versions) {
$lang = $this->getLang(); $lang = $this->getLang();
@ -336,7 +335,7 @@ class DocumentationViewer extends Controller {
*/ */
function getEntities($version = false, $lang = false) { function getEntities($version = false, $lang = false) {
$entities = DocumentationService::get_registered_entities($version, $lang); $entities = DocumentationService::get_registered_entities($version, $lang);
$output = new DataObjectSet(); $output = new ArrayList();
$currentEntity = $this->getEntity(); $currentEntity = $this->getEntity();
@ -349,7 +348,7 @@ class DocumentationViewer extends Controller {
$content = false; $content = false;
if($page = $entity->getIndexPage($version, $lang)) { 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( $output->push(new ArrayData(array(
@ -457,7 +456,7 @@ class DocumentationViewer extends Controller {
* *
* @todo this only handles 2 levels. Could make it recursive * @todo this only handles 2 levels. Could make it recursive
* *
* @return false|DataObjectSet * @return false|ArrayList
*/ */
function getEntityPages() { function getEntityPages() {
if($entity = $this->getEntity()) { if($entity = $this->getEntity()) {
@ -493,7 +492,7 @@ class DocumentationViewer extends Controller {
* @param DocumentationEntity * @param DocumentationEntity
* @param int Depth of page in the tree * @param int Depth of page in the tree
* *
* @return DataObjectSet|false * @return ArrayList|false
*/ */
private function _getEntityPagesNested(&$page, $entity, $level = 0) { private function _getEntityPagesNested(&$page, $entity, $level = 0) {
if(isset($this->Remaining[$level])) { if(isset($this->Remaining[$level])) {
@ -556,7 +555,7 @@ class DocumentationViewer extends Controller {
$page = $this->getPage(); $page = $this->getPage();
if($page) { 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. // 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 * Generate a list of breadcrumbs for the user. Based off the remaining params
* in the url * in the url
* *
* @return DataObjectSet * @return ArrayList
*/ */
function getBreadcrumbs() { function getBreadcrumbs() {
if(!$this->Remaining) $this->Remaining = array(); if(!$this->Remaining) $this->Remaining = array();
$pages = array_merge(array($this->entity), $this->Remaining); $pages = array_merge(array($this->entity), $this->Remaining);
$output = new DataObjectSet(); $output = new ArrayList();
if($pages) { if($pages) {
$path = array(); $path = array();
@ -690,7 +689,7 @@ class DocumentationViewer extends Controller {
function LanguageForm() { function LanguageForm() {
$langs = $this->getLanguages(); $langs = $this->getLanguages();
$fields = new FieldSet( $fields = new FieldList(
$dropdown = new DropdownField( $dropdown = new DropdownField(
'LangCode', 'LangCode',
_t('DocumentationViewer.LANGUAGE', 'Language'), _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')) new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change'))
); );
@ -749,13 +748,13 @@ class DocumentationViewer extends Controller {
if(!DocumentationSearch::enabled()) return false; if(!DocumentationSearch::enabled()) return false;
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : ""; $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
$fields = new FieldSet( $fields = new FieldList(
new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q), new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q),
new HiddenField('Entities', '', implode(',', array_keys($this->getSearchedEntities()))), new HiddenField('Entities', '', implode(',', array_keys($this->getSearchedEntities()))),
new HiddenField('Versions', '', implode(',', $this->getSearchedVersions())) new HiddenField('Versions', '', implode(',', $this->getSearchedVersions()))
); );
$actions = new FieldSet( $actions = new FieldList(
new FormAction('results', 'Search') new FormAction('results', 'Search')
); );
@ -824,7 +823,7 @@ class DocumentationViewer extends Controller {
*/ */
function getSearchQuery() { function getSearchQuery() {
if(isset($_REQUEST['Search'])) { 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() : ""; $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
// klude to take an array of objects down to a simple map // 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'); $entities = $entities->map('Folder', 'Title');
// if we haven't gone any search limit then we're searching everything // if we haven't gone any search limit then we're searching everything
@ -877,7 +876,7 @@ class DocumentationViewer extends Controller {
$searchedVersions = $this->getSearchedVersions(); $searchedVersions = $this->getSearchedVersions();
if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions; if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions;
$fields = new FieldSet( $fields = new FieldList(
new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q),
new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities), new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities),
new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'), 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')) new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search'))
); );
$required = new RequiredFields(array('Search')); $required = new RequiredFields(array('Search'));
@ -920,13 +919,13 @@ class DocumentationViewer extends Controller {
if($version == "trunk" || $compare > 0) { if($version == "trunk" || $compare > 0) {
return $this->customise(new ArrayData(array( return $this->customise(new ArrayData(array(
'FutureRelease' => true, 'FutureRelease' => true,
'StableVersion' => DBField::create('HTMLText', $stable) 'StableVersion' => DBField::create_field('HTMLText', $stable)
))); )));
} }
else { else {
return $this->customise(new ArrayData(array( return $this->customise(new ArrayData(array(
'OutdatedRelease' => true, 'OutdatedRelease' => true,
'StableVersion' => DBField::create('HTMLText', $stable) 'StableVersion' => DBField::create_field('HTMLText', $stable)
))); )));
} }
} }

View File

@ -113,8 +113,9 @@ class DocumentationPage extends ViewableData {
} }
/** /**
* @param String - has to be plain text for open search compatibility. * @param string - has to be plain text for open search compatibility.
* @return String *
* @return string
*/ */
function getBreadcrumbTitle($divider = ' - ') { function getBreadcrumbTitle($divider = ' - ') {
$pathParts = explode('/', $this->getRelativePath()); $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 * @return string
*/ */
function Link() { function getLink() {
if($entity = $this->getEntity()) { if($entity = $this->getEntity()) {
$link = Controller::join_links($entity->Link($this->getVersion(), $this->lang), $this->getRelativeLink()); $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 * Set a variable from the metadata field on this class
* *
* @param String key * @param string key
* @param mixed value * @param mixed value
*/ */
public function setMetaData($key, $value) { public function setMetaData($key, $value) {
@ -243,9 +244,9 @@ class DocumentationPage extends ViewableData {
/** /**
* Parse a file (with a lang and a version). * Parse a file (with a lang and a version).
* *
* @param String $baselink * @param string $baselink
* *
* @return String * @return string
*/ */
function getHTML($version, $lang = 'en') { function getHTML($version, $lang = 'en') {
return DocumentationParser::parse($this, $this->entity->getRelativeLink($version, $lang)); return DocumentationParser::parse($this, $this->entity->getRelativeLink($version, $lang));

View File

@ -15,21 +15,21 @@ class DocumentationPageTest extends SapphireTest {
$page->setEntity($entity); $page->setEntity($entity);
// single layer // 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 = new DocumentationPage();
$folder->setRelativePath('sort'); $folder->setRelativePath('sort');
$folder->setEntity($entity); $folder->setEntity($entity);
// folder, should have a trailing slash // folder, should have a trailing slash
$this->assertStringEndsWith('testmodule/en/sort/', $folder->Link()); $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link);
// second // second
$nested = new DocumentationPage(); $nested = new DocumentationPage();
$nested->setRelativePath('subfolder/subpage.md'); $nested->setRelativePath('subfolder/subpage.md');
$nested->setEntity($entity); $nested->setEntity($entity);
$this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link()); $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link);
// test with version. // test with version.
$entity = DocumentationService::register("versionlinks", DOCSVIEWER_PATH ."/tests/docs-v2.4/", '1'); $entity = DocumentationService::register("versionlinks", DOCSVIEWER_PATH ."/tests/docs-v2.4/", '1');
@ -40,7 +40,7 @@ class DocumentationPageTest extends SapphireTest {
$page->setRelativePath('test.md'); $page->setRelativePath('test.md');
$page->setEntity($entity); $page->setEntity($entity);
$page->setVersion('1'); $page->setVersion('1');
$this->assertStringEndsWith('versionlinks/en/1/test', $page->Link()); $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link);
} }

View File

@ -133,7 +133,6 @@ class DocumentationViewerTest extends FunctionalTest {
} }
$links = $pages->column('Link'); $links = $pages->column('Link');
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/sort/', $links[0]); $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/sort/', $links[0]);
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/', $links[1]); $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/', $links[1]);
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/test', $links[2]); $this->assertStringEndsWith('DocumentationViewerTests/en/2.3/test', $links[2]);