From f36a285e112ee5d37da5e25e5b7910ef5f5918bb Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 28 Apr 2015 15:14:02 +0200 Subject: [PATCH] Move searchdb inside app/upload/plugins/xapian/searchdb --- .gitignore | 18 +--- .travis.yml | 2 +- README.md | 2 +- .../plugins/xapian/searchdb}/index.html | 0 main/admin/settings.lib.php | 2 +- main/inc/lib/search/IndexableChunk.class.php | 19 +++-- .../lib/search/xapian/XapianIndexer.class.php | 85 +++++++++++-------- main/inc/lib/search/xapian/XapianQuery.php | 2 +- .../install/update-files-1.9.0-1.10.0.inc.php | 2 + main/search/INSTALL | 18 ++-- robots.txt | 4 +- 11 files changed, 78 insertions(+), 76 deletions(-) rename {searchdb => app/upload/plugins/xapian/searchdb}/index.html (100%) mode change 100755 => 100644 diff --git a/.gitignore b/.gitignore index 55fef0760b..981bd95e08 100755 --- a/.gitignore +++ b/.gitignore @@ -17,28 +17,14 @@ courses/* !courses/index.html # Home -app/home/* home/* -# User images -app/upload/users/* -!app/upload/users/index.html - -# Session images -app/upload/sessions/* -!main/upload/sessions/index.html - -# Course images -app/upload/courses/* -!app/upload/courses/index.html +# Upload content +app/upload/* # Logs and databases # *.log -# Xapian indexes directory -searchdb/* -!searchdb/index.html - # IDE settings .idea diff --git a/.travis.yml b/.travis.yml index 0c1429262e..e3c2d63f0b 100755 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ before_script: - cp chamilo-cli-install/chamilo-cli-installer.php main/install/ - mysql -u root -e 'create database chamilo' # install Chamilo with Chash - see reference https://github.com/sonnym/travis-ci-drupal-module-example/blob/master/.travis.yml - - sudo chmod -R 0777 app/cache courses home app/upload/ main/default_course_document/images main/inc/conf searchdb main/lang main/css + - sudo chmod -R 0777 app/config app/cache app/courses home app/upload/ main/default_course_document/images main/lang main/css - cd main/install/ - sudo php5 chamilo-cli-installer.php -l admin -p admin -U travis -u 'http://localhost/' -X travis -L english -z 'admin@example.com' -f 'John' -g 'Doe' -b '555-5555' -c 'Test campus' -y 'Chamilo' -x 'https://chamilo.org' - cd ../.. diff --git a/README.md b/README.md index 8552dbdf95..5e00a60cef 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ composer update On a Debian-based system, launch: ``` -sudo chown -R www-data:www-data app/cache course home searchdb app/upload/users app/upload/sessions app/upload/courses main/default_course_document/images main/lang main/css main/inc/conf +sudo chown -R www-data:www-data app/cache app/config app/course home app/upload main/default_course_document/images main/lang main/css ``` ### Start the installer diff --git a/searchdb/index.html b/app/upload/plugins/xapian/searchdb/index.html old mode 100755 new mode 100644 similarity index 100% rename from searchdb/index.html rename to app/upload/plugins/xapian/searchdb/index.html diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index 32599bed08..259de1b306 100755 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -656,7 +656,7 @@ function handle_search() echo ''; if ($search_enabled == 'true') { - $xapian_path = api_get_path(SYS_PATH).'searchdb'; + $xapian_path = api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb'; /* @todo Test the Xapian connection diff --git a/main/inc/lib/search/IndexableChunk.class.php b/main/inc/lib/search/IndexableChunk.class.php index 4ee9f7a648..4ef1df139d 100755 --- a/main/inc/lib/search/IndexableChunk.class.php +++ b/main/inc/lib/search/IndexableChunk.class.php @@ -1,12 +1,10 @@ addTerm($course_id, XAPIAN_PREFIX_COURSEID); } /** * Let add tool id term */ - public function addToolId($tool_id) { + public function addToolId($tool_id) + { $this->addTerm($tool_id, XAPIAN_PREFIX_TOOLID); } - } diff --git a/main/inc/lib/search/xapian/XapianIndexer.class.php b/main/inc/lib/search/xapian/XapianIndexer.class.php index 1932916c6f..bf48cd7bdb 100755 --- a/main/inc/lib/search/xapian/XapianIndexer.class.php +++ b/main/inc/lib/search/xapian/XapianIndexer.class.php @@ -1,12 +1,9 @@ db = null; + $this->stemmer = null; + } + /** * Generates a list of languages Xapian manages * @@ -33,7 +40,8 @@ abstract class XapianIndexer { * Chamilo languages and Xapian languages (through hardcoding) * @return array Array of languages codes -> Xapian languages */ - public final function xapian_languages() { + public final function xapian_languages() + { /* http://xapian.org/docs/apidoc/html/classXapian_1_1Stem.html */ return array( 'none' => 'none', //don't stem terms @@ -60,14 +68,15 @@ abstract class XapianIndexer { /** * Connect to the database, and create it if it doesn't exist */ - function connectDb($path = NULL, $dbMode = NULL, $lang = 'english') { - if ($this->db != NULL) + function connectDb($path = null, $dbMode = null, $lang = 'english') + { + if ($this->db != null) return $this->db; - if ($dbMode == NULL) + if ($dbMode == null) $dbMode = Xapian::DB_CREATE_OR_OPEN; - if ($path == NULL) - $path = api_get_path(SYS_PATH) . 'searchdb/'; + if ($path == null) + $path = api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb/'; try { $this->db = new XapianWritableDatabase($path, $dbMode); @@ -82,6 +91,7 @@ abstract class XapianIndexer { return $this->db; } catch (Exception $e) { Display::display_error_message($e->getMessage()); + return 1; } } @@ -90,7 +100,8 @@ abstract class XapianIndexer { * Simple getter for the db attribute * @return object The db attribute */ - function getDb() { + function getDb() + { return $this->db; } @@ -99,16 +110,18 @@ abstract class XapianIndexer { * @param string Chunk of text * @return void */ - function addChunk($chunk) { + function addChunk($chunk) + { $this->chunks[] = $chunk; } /** * Actually index the current data * - * @return integer New Xapian document ID or NULL upon failure + * @return integer New Xapian document ID or null upon failure */ - function index() { + function index() + { try { if (!empty($this->chunks)) { foreach ($this->chunks as $chunk) { @@ -148,8 +161,9 @@ abstract class XapianIndexer { * @param int did Xapian::docid * @return mixed XapianDocument, or false on error */ - function get_document($did) { - if ($this->db == NULL) { + function get_document($did) + { + if ($this->db == null) { $this->connectDb(); } try { @@ -167,8 +181,9 @@ abstract class XapianIndexer { * @param XapianDocument $doc xapian document to push into the db * @return mixed xapian document data or FALSE if error */ - function get_document_data($doc) { - if ($this->db == NULL) { + function get_document_data($doc) + { + if ($this->db == null) { $this->connectDb(); } try { @@ -191,7 +206,8 @@ abstract class XapianIndexer { * @param string $prefix Prefix used to categorize the doc (usually 'T' for title, 'A' for author) * @return boolean false on error */ - function update_terms($did, $terms, $prefix) { + function update_terms($did, $terms, $prefix) + { $doc = $this->get_document($did); if ($doc === false) { return false; @@ -203,6 +219,7 @@ abstract class XapianIndexer { } $this->db->replace_document($did, $doc); $this->db->flush(); + return true; } @@ -211,8 +228,9 @@ abstract class XapianIndexer { * * @param int did Xapian::docid */ - function remove_document($did) { - if ($this->db == NULL) { + function remove_document($did) + { + if ($this->db == null) { $this->connectDb(); } if (is_numeric($did) && $did > 0) { @@ -231,7 +249,8 @@ abstract class XapianIndexer { * @param XapianDocument $doc The xapian document where to add the term * @return mixed XapianDocument, or false on error */ - function add_term_to_doc($term, $doc) { + function add_term_to_doc($term, $doc) + { if (!is_a($doc, 'XapianDocument')) { return FALSE; } @@ -250,7 +269,8 @@ abstract class XapianIndexer { * @param XapianDocument $doc The xapian document where to add the term * @return mixed XapianDocument, or false on error */ - function remove_term_from_doc($term, $doc) { + function remove_term_from_doc($term, $doc) + { if (!is_a($doc, 'XapianDocument')) { return FALSE; } @@ -268,11 +288,12 @@ abstract class XapianIndexer { * @param XapianDocument $doc xapian document to push into the db * @param Xapian::docid $did xapian document id of the document to replace */ - function replace_document($doc, $did) { + function replace_document($doc, $did) + { if (!is_a($doc, 'XapianDocument')) { return FALSE; } - if ($this->db == NULL) { + if ($this->db == null) { $this->connectDb(); } try { @@ -284,20 +305,14 @@ abstract class XapianIndexer { } } - /** - * Class contructor - */ - function __construct() { - $this->db = NULL; - $this->stemmer = NULL; - } /** * Class destructor */ - function __destruct() { + function __destruct() + { unset($this->db); unset($this->stemmer); } -} \ No newline at end of file +} diff --git a/main/inc/lib/search/xapian/XapianQuery.php b/main/inc/lib/search/xapian/XapianQuery.php index 6068bbec7b..70c3b09ba4 100755 --- a/main/inc/lib/search/xapian/XapianQuery.php +++ b/main/inc/lib/search/xapian/XapianQuery.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../IndexableChunk.class.php'; //TODO: think another way without including specific fields here require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; -define('XAPIAN_DB', api_get_path(SYS_PATH) . 'searchdb/'); +define('XAPIAN_DB', api_get_path(SYS_UPLOAD_PATH) . 'plugins/xapian/searchdb/'); /** * Queries the database. diff --git a/main/install/update-files-1.9.0-1.10.0.inc.php b/main/install/update-files-1.9.0-1.10.0.inc.php index c4f5b44d1d..35ccc0e0fd 100644 --- a/main/install/update-files-1.9.0-1.10.0.inc.php +++ b/main/install/update-files-1.9.0-1.10.0.inc.php @@ -86,6 +86,7 @@ if (defined('SYSTEM_INSTALLATION')) { 'xhosa', 'yoruba', ); + $filesToDelete = array( 'accessibility', 'admin', @@ -169,6 +170,7 @@ if (defined('SYSTEM_INSTALLATION')) { api_get_path(SYS_CODE_PATH).'upload/users' => api_get_path(SYS_UPLOAD_PATH).'users', api_get_path(SYS_CODE_PATH).'upload/badges' => api_get_path(SYS_UPLOAD_PATH).'badges', api_get_path(SYS_PATH).'courses' => api_get_path(SYS_COURSE_PATH), + api_get_path(SYS_PATH).'searchdb' => api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb', ]; foreach ($movePathList as $origin => $destination) { diff --git a/main/search/INSTALL b/main/search/INSTALL index 7da0dff0cf..4a0f6f4d86 100755 --- a/main/search/INSTALL +++ b/main/search/INSTALL @@ -1,4 +1,4 @@ -INSTALLATION +INSTALLATION On Debian Lenny Base install @@ -8,8 +8,8 @@ On Debian Lenny http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=493944 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=493941 on dokeos root: - mkdir searchdb - chmod 777 searchdb (or equivalent) + mkdir app/upload/plugins/xapian/searchdb + chmod 777 app/upload/plugins/xapian/searchdb (or equivalent) Useful xapian development tools apt-get install xapian-doc xapian-tools (See delve command) @@ -23,14 +23,14 @@ Chamilo 1.8.8 + XAPIAN in Ubuntu 10.10 2. Go to main/admin/specific_fields.php and Specific fields (Those are text fields that will be add in documents, exercises, links in order to index data) i.e i.e. Author, Body part, Technology, Topic 3. Go to main/admin/settings.php?category=Search and set a Specific field by default -4. Install the Xapian module for PHP5 +4. Install the Xapian module for PHP5 sudo apt-get install php5-xapian 5. Install the imagemagick modules sudo apt-get install imagemagick - sudo apt-get install php5-imagick + sudo apt-get install php5-imagick 6. In Chamilo root - mkdir searchdb - sudo chmod 777 searchdb + mkdir app/upload/plugins/xapian/searchdb + sudo chmod 777 app/upload/plugins/xapian/searchdb 7. Useful Xapian development tools sudo apt-get install xapian-doc xapian-tools 8. Restart Apache @@ -52,14 +52,14 @@ build packages: env PHP_VERSIONS=5 debian/rules maint sed -i 's!include_path=php5$!include_path=$(srcdir)/php5!' php/Makefile.in echo auto-commit >> debian/source/options - debuild -e PHP_VERSIONS=5 -us -uc + debuild -e PHP_VERSIONS=5 -us -uc cd .. If you're using PHP 5.4, then subclassing Xapian classes in PHP doesn't currently work properly and the testsuite will fail with a segmentation fault. The wrappers work otherwise, so if that's all you need, you can build the package without running the testsuite by changing the penultimate command above to: -env DEB_BUILD_OPTIONS=nocheck debuild -e PHP_VERSIONS=5 -us -uc +env DEB_BUILD_OPTIONS=nocheck debuild -e PHP_VERSIONS=5 -us -uc Then you can install the built package: diff --git a/robots.txt b/robots.txt index f4d1c90975..3d25b9bd2d 100755 --- a/robots.txt +++ b/robots.txt @@ -18,14 +18,12 @@ User-Agent: * # Directories Disallow: /app/cache/ Disallow: /app/logs/ +Disallow: /app/upload/ Disallow: /app/courses/ -Disallow: /courses/ Disallow: /documentation/ -Disallow: /app/home/ Disallow: /home/ Disallow: /main/ Disallow: /plugin/ -Disallow: /searchdb/ Disallow: /tests/ # Files