From 3500c39567617655710a5790485558e3731dae50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 1 Aug 2013 22:49:43 +0200 Subject: [PATCH 1/5] adding new cli script to rescan files --- scanFiles.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 scanFiles.php diff --git a/scanFiles.php b/scanFiles.php new file mode 100644 index 00000000000..2144fce5d5a --- /dev/null +++ b/scanFiles.php @@ -0,0 +1,37 @@ +" . PHP_EOL; + echo " will rescan all files of the given user" . PHP_EOL; + echo " php scanFiles.php --all" . PHP_EOL; + echo " will rescan all files of all known users" . PHP_EOL; + return; +} + +function scanFiles($user) { + $scanner = new \OC\Files\Utils\Scanner($user); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) { + echo "Scanning $path" . PHP_EOL; + }); + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) { + echo "Scanning $path" . PHP_EOL; + }); + $scanner->scan(''); +} + +if ($argv[1] === '--all') { + $users = OC_User::getUsers(); +} else { + $users = array($argv[1]); +} + +foreach ($users as $user) { + scanFiles($user); +} From a7a05b321afd0085bd0e8c068c95e654d229e27c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 2 Aug 2013 15:36:54 +0200 Subject: [PATCH 2/5] Use console.php entry point for file scanning from console --- scanFiles.php => apps/files/console/scan.php | 2 -- console.php | 25 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) rename scanFiles.php => apps/files/console/scan.php (95%) create mode 100644 console.php diff --git a/scanFiles.php b/apps/files/console/scan.php similarity index 95% rename from scanFiles.php rename to apps/files/console/scan.php index 2144fce5d5a..118e586aea3 100644 --- a/scanFiles.php +++ b/apps/files/console/scan.php @@ -1,7 +1,5 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$RUNTIME_NOAPPS = true; +require_once 'lib/base.php'; + +// Don't do anything if ownCloud has not been installed yet +if (!OC_Config::getValue('installed', false)) { + exit(0); +} + +if (OC::$CLI) { + if ($argc > 1 && $argv[1] === 'files:scan') { + require_once 'apps/files/console/scan.php'; + } +} +else +{ + echo "This script can be run from the command line only\n"; +} From 5e1a775016ef9eca6d05c0503996650688e39575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 2 Aug 2013 21:23:26 +0200 Subject: [PATCH 3/5] adjust usage text --- apps/files/console/scan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/console/scan.php b/apps/files/console/scan.php index 118e586aea3..b9eccfb9934 100644 --- a/apps/files/console/scan.php +++ b/apps/files/console/scan.php @@ -6,9 +6,9 @@ if (!OC::$CLI) { } if (count($argv) !== 2) { echo "Usage:" . PHP_EOL; - echo " php scanFiles.php " . PHP_EOL; + echo " files:scan " . PHP_EOL; echo " will rescan all files of the given user" . PHP_EOL; - echo " php scanFiles.php --all" . PHP_EOL; + echo " files:scan --all" . PHP_EOL; echo " will rescan all files of all known users" . PHP_EOL; return; } From 58f369d0290feed5c2bc026b22e9ce74d8e85c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 2 Aug 2013 21:23:50 +0200 Subject: [PATCH 4/5] more verbose printouts - fixing execution --- console.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/console.php b/console.php index a3b1357a287..538837a04b4 100644 --- a/console.php +++ b/console.php @@ -11,15 +11,26 @@ require_once 'lib/base.php'; // Don't do anything if ownCloud has not been installed yet if (!OC_Config::getValue('installed', false)) { + echo "Console can only be used once ownCloud has been installed" . PHP_EOL; exit(0); } -if (OC::$CLI) { - if ($argc > 1 && $argv[1] === 'files:scan') { - require_once 'apps/files/console/scan.php'; - } +if (!OC::$CLI) { + echo "This script can be run from the command line only" . PHP_EOL; + exit(0); +} + +if ($argc < 1) { + echo "Usage:" . PHP_EOL; + echo " php console.php " . PHP_EOL; + exit(0); } -else -{ - echo "This script can be run from the command line only\n"; + +$command = $argv[1]; +array_shift($argv); + +if ($command === 'files:scan') { + require_once 'apps/files/console/scan.php'; +} else { + echo "Unknown command '$command'" . PHP_EOL; } From 010c4e0b833409e233b60c2a833485d2f1a34989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 2 Aug 2013 21:28:04 +0200 Subject: [PATCH 5/5] remove cli check --- apps/files/console/scan.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/files/console/scan.php b/apps/files/console/scan.php index b9eccfb9934..70183fc888a 100644 --- a/apps/files/console/scan.php +++ b/apps/files/console/scan.php @@ -1,9 +1,5 @@ " . PHP_EOL;