From f6efa1df866c142000beda30ac8475e10bcd12ae Mon Sep 17 00:00:00 2001 From: Mike Andrewartha Date: Tue, 9 Feb 2016 17:57:27 +1300 Subject: [PATCH] added crontask and updatetask buildtask as per userhelp, repositories yml, updated robots file, removed update shell script --- app/_config.php | 4 +- app/_config/config.yml | 2 +- app/_config/docs-repositiories.yml | 32 ++++++++ app/_config/routes.yml | 2 +- app/code/UpdateDocsCronTask.php | 27 +++++++ app/code/UpdateTask.php | 116 +++++++++++++++++++++++++++++ bin/update.sh | 52 ------------- robots.txt | 3 +- 8 files changed, 179 insertions(+), 59 deletions(-) create mode 100644 app/_config/docs-repositiories.yml create mode 100644 app/code/UpdateDocsCronTask.php create mode 100644 app/code/UpdateTask.php delete mode 100755 bin/update.sh diff --git a/app/_config.php b/app/_config.php index 9d63437..120b348 100644 --- a/app/_config.php +++ b/app/_config.php @@ -58,9 +58,7 @@ Config::inst()->update('DocumentationSearch', 'boost_by_path', array( )); // Set shared index (avoid issues with different temp paths between CLI and web users) -if(file_exists(BASE_PATH . '/.lucene-index')) { - Config::inst()->update('DocumentationSearch', 'index_location', BASE_PATH . '/.lucene-index'); -} +Config::inst()->update('DocumentationSearch', 'index_location', BASE_PATH . '/assets/.lucene-index'); // Fix invalid character in iconv // see http://stackoverflow.com/questions/4723135/invalid-characters-for-lucene-text-search diff --git a/app/_config/config.yml b/app/_config/config.yml index d1ac530..c27c045 100644 --- a/app/_config/config.yml +++ b/app/_config/config.yml @@ -9,4 +9,4 @@ StaticExporter: disable_sitetree_export: true Controller: extensions: - - ControllerExtension + - ControllerExtension \ No newline at end of file diff --git a/app/_config/docs-repositiories.yml b/app/_config/docs-repositiories.yml new file mode 100644 index 0000000..4b3b43e --- /dev/null +++ b/app/_config/docs-repositiories.yml @@ -0,0 +1,32 @@ +--- +Name: docs-repos +After: + - framework/* + - cms/* +--- +UpdateTask: + documentation_repositories: + - + - silverstripe/silverstripe-framework + - framework + - master + - + - silverstripe/silverstripe-framework + - framework + - "3.2" + - + - silverstripe/silverstripe-framework + - framework + - "3.1" + - + - silverstripe/silverstripe-framework + - framework + - "3.0" + - + - silverstripe/silverstripe-framework + - framework + - "3" + - + - silverstripe/silverstripe-framework + - framework + - "2.4" \ No newline at end of file diff --git a/app/_config/routes.yml b/app/_config/routes.yml index 541719a..e74f2f7 100644 --- a/app/_config/routes.yml +++ b/app/_config/routes.yml @@ -1,5 +1,5 @@ --- -Name: docs +Name: docs-routes After: framework/routes#coreroutes --- Director: diff --git a/app/code/UpdateDocsCronTask.php b/app/code/UpdateDocsCronTask.php new file mode 100644 index 0000000..55ea5ae --- /dev/null +++ b/app/code/UpdateDocsCronTask.php @@ -0,0 +1,27 @@ +run(null); + + //reindex the search + $searchtask = new RebuildLuceneDocsIndex(); + $searchtask->run(null); + + } +} \ No newline at end of file diff --git a/app/code/UpdateTask.php b/app/code/UpdateTask.php new file mode 100644 index 0000000..49e589a --- /dev/null +++ b/app/code/UpdateTask.php @@ -0,0 +1,116 @@ +printLine("updating..."); + + $repositories = $this->getRepositories(); + + foreach ($repositories as $repository) { + $this->cloneRepository($repository); + $this->cleanRepository($repository); + } + } + + /** + * @return string + * + * @todo document this new configuration parameter + */ + private function getPath() + { + return ASSETS_PATH; + } + + /** + * @param string $message + */ + private function printLine($message) + { + $this->eol = Director::is_cli() ? PHP_EOL : "
"; + print $message . $this->eol; + flush(); + } + + /** + * Returns the array of repos to source markdown docs from + * + * @return array + * + */ + private function getRepositories() + { + if($repos = $this->config()->documentation_repositories) + { + return $repos; + } else { + user_error("You need to set 'UpdateTask:documentation_repositories' array in your yaml configuration", E_USER_WARNING); + return null; + } + } + + /** + * @param array $repository + * + * @todo test this works with all modules + */ + private function cloneRepository(array $repository) + { + list($remote, $folder, $branch) = $repository; + + $path = $this->getPath(); + + if (!file_exists("{$path}/src")) { + mkdir("{$path}/src"); + } + + if (!file_exists("{$path}/src/{$folder}_{$branch}")) { + $this->printLine("cloning " . $remote . "/" . $branch); + + chdir("{$path}/src"); + exec("git clone -q git://github.com/{$remote}.git {$folder}_{$branch} --quiet"); + } + + chdir("{$path}/src/{$folder}_{$branch}"); + exec("git fetch origin"); + exec("git checkout -q origin/{$branch}"); + } + + /** + * Clears out any non markdown files stored in assets + * + * @param array $repository + */ + private function cleanRepository(array $repository) + { + $files = array_merge(glob("*"), glob(".*")); + + foreach ($files as $file) { + if ($file !== "docs" && $file !== "." && $file !== "..") { + exec("rm -rf {$file}"); + } + } + } +} \ No newline at end of file diff --git a/bin/update.sh b/bin/update.sh deleted file mode 100755 index ed529de..0000000 --- a/bin/update.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -dir=$1/assets - -if [ ! "$dir" ]; then - echo "Usage: $0 /base/folder/to/docs" - exit 1 -fi - -#=== FUNCTION ================================================================ -# NAME: checkout -# DESCRIPTION: Checks out a specific branch of a module into a folder. Not -# particular good for taking up space, but at the moment separate -# folders for each version we need will do. -# -# The master branch will checked out by default -# PARAMETERS: -# $1 - module path on github (e.g silverstripe/sapphire.git) -# $2 - branch name (e.g 3.0) -# $3 - module name (e.g sapphire) -# -#=============================================================================== -# Parameters: github path -function checkout { - # Create dirs - if [ ! -d $dir/src ]; then - mkdir $dir/src - fi - - if [ ! -d $dir/src/$2_$3 ]; then - echo "Cloning $1 branch $3" - cd $dir/src - git clone -b $3 --depth=100 git://github.com/$1 $dir/src/$2_$3 --quiet - else - echo "Updating $2 from branch $3" - cd $dir/src/$2_$3 - git reset --hard -q - git fetch origin -q - git pull -q origin $3 - fi -} - -# core -checkout 'silverstripe/silverstripe-framework.git' 'framework' 'master' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '3' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '3.3' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '3.2' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '3.1' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '3.0' -checkout 'silverstripe/silverstripe-framework.git' 'framework' '2.4' - -echo "Done." \ No newline at end of file diff --git a/robots.txt b/robots.txt index 0900ed8..8966131 100644 --- a/robots.txt +++ b/robots.txt @@ -1,6 +1,5 @@ User-agent: * Disallow: /admin Disallow: /assets/src -Disallow: /en/4.0/ -Disallow: /en/3.3/ +Disallow: /assets/.lucene-index Crawl-Delay: 4 \ No newline at end of file