Merge pull request #4285 from owncloud/scan-files-script-master

adding new cli script to rescan files
This commit is contained in:
Thomas Müller 2013-08-05 01:09:15 -07:00
commit bf1a9dfae3
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
if (count($argv) !== 2) {
echo "Usage:" . PHP_EOL;
echo " files:scan <user_id>" . PHP_EOL;
echo " will rescan all files of the given user" . PHP_EOL;
echo " files:scan --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);
}

36
console.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
* 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)) {
echo "Console can only be used once ownCloud has been installed" . PHP_EOL;
exit(0);
}
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 <command>" . PHP_EOL;
exit(0);
}
$command = $argv[1];
array_shift($argv);
if ($command === 'files:scan') {
require_once 'apps/files/console/scan.php';
} else {
echo "Unknown command '$command'" . PHP_EOL;
}