Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/previewgenerator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-03-15 00:11:29 +0300
committerGitHub <noreply@github.com>2017-03-15 00:11:29 +0300
commit3272ea47043e46f77b4a7885e0849c6f7f8ea382 (patch)
tree38c5d4f3719b611454ac4f2ca060eb0c6be79249
parent3371d587e7f2434298f75847eb4e9026ab561fce (diff)
parent03be88f9d5d55f2fd48bf6d4d1589463aa137c2d (diff)
Merge pull request #34 from rullzer/fix_2v1.0.4v1.0.3
Add check for already running command
-rw-r--r--appinfo/app.php2
-rw-r--r--lib/Command/PreGenerate.php37
2 files changed, 36 insertions, 3 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
index 20f59df..5f11dfb 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -20,4 +20,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-$app = new \OCA\PreviewGenerator\AppInfo\Application('PreviewGenerator');
+$app = new \OCA\PreviewGenerator\AppInfo\Application('previewgenerator');
diff --git a/lib/Command/PreGenerate.php b/lib/Command/PreGenerate.php
index aa2a0b0..b401d7e 100644
--- a/lib/Command/PreGenerate.php
+++ b/lib/Command/PreGenerate.php
@@ -22,6 +22,7 @@
*/
namespace OCA\PreviewGenerator\Command;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Encryption\IManager;
use OCP\Files\File;
use OCP\Files\Folder;
@@ -37,6 +38,9 @@ use Symfony\Component\Console\Output\OutputInterface;
class PreGenerate extends Command {
+ /** @var string */
+ protected $appName;
+
/** @var IUserManager */
protected $userManager;
@@ -61,28 +65,37 @@ class PreGenerate extends Command {
/** @var IManager */
protected $encryptionManager;
+ /** @var ITimeFactory */
+ protected $time;
+
/**
+ * @param string $appName
* @param IRootFolder $rootFolder
* @param IUserManager $userManager
* @param IPreview $previewGenerator
* @param IConfig $config
* @param IDBConnection $connection
* @param IManager $encryptionManager
+ * @param ITimeFactory $time
*/
- public function __construct(IRootFolder $rootFolder,
+ public function __construct($appName,
+ IRootFolder $rootFolder,
IUserManager $userManager,
IPreview $previewGenerator,
IConfig $config,
IDBConnection $connection,
- IManager $encryptionManager) {
+ IManager $encryptionManager,
+ ITimeFactory $time) {
parent::__construct();
+ $this->appName = $appName;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->previewGenerator = $previewGenerator;
$this->config = $config;
$this->connection = $connection;
$this->encryptionManager = $encryptionManager;
+ $this->time = $time;
}
protected function configure() {
@@ -102,11 +115,21 @@ class PreGenerate extends Command {
return 1;
}
+ $lastActivity = (int)$this->config->getAppValue($this->appName, 'lastActivity', 0);
+
+ if (($this->time->getTime() - $lastActivity) < 30 * 60 * 60) {
+ $output->writeln('Command is already running.');
+ return 2;
+ }
+
+ $this->updateLastActivity();
$this->output = $output;
$this->calculateSizes();
$this->startProcessing();
+ $this->clearLastActivity();
+
return 0;
}
@@ -195,6 +218,8 @@ class PreGenerate extends Command {
// Maybe log that previews could not be generated?
}
}
+
+ $this->updateLastActivity();
}
private function processFolder(Folder $folder) {
@@ -238,4 +263,12 @@ class PreGenerate extends Command {
$h *= 2;
}
}
+
+ private function updateLastActivity() {
+ $this->config->setAppValue($this->appName, 'lastActivity', $this->time->getTime());
+ }
+
+ private function clearLastActivity() {
+ $this->config->deleteAppValue($this->appName, 'lastActivity');
+ }
}