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

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-08-03 19:59:07 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-08-03 19:59:07 +0300
commitb023c7e87810cda9e935c5011f7494e7570de994 (patch)
tree611cf89bca8ecc16a5f7bdb0b1a6c3c4d3dc1512 /lib
parent50bedc5bd695b74582e5f6702c8ee99e744476cd (diff)
events
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/CliService.php56
-rw-r--r--lib/Service/IndexService.php46
2 files changed, 90 insertions, 12 deletions
diff --git a/lib/Service/CliService.php b/lib/Service/CliService.php
index f6f39a8..19338f2 100644
--- a/lib/Service/CliService.php
+++ b/lib/Service/CliService.php
@@ -66,6 +66,8 @@ class CliService {
*/
public function setRunner(Runner $runner) {
$this->runner = $runner;
+
+ $this->runner->onInfoUpdate([$this, 'onInfoUpdated']);
}
@@ -105,7 +107,7 @@ class CliService {
/**
* @param string $panelSlot
*
- * @return mixed
+ * @return string
*/
public function currentPanel($panelSlot) {
foreach ($this->displayedPanel as $panel) {
@@ -113,6 +115,8 @@ class CliService {
return $panel['id'];
}
}
+
+ return '';
}
@@ -136,10 +140,12 @@ class CliService {
/**
* @param OutputInterface $output
+ * @param array $initVar
*/
- public function runDisplay(OutputInterface $output) {
+ public function runDisplay(OutputInterface $output, $initVar = []) {
$this->output = $output;
+ $output->writeLn('');
foreach ($this->displayedPanel as $displayedPanel) {
$panel = $this->panels[$displayedPanel['id']];
for ($i = 0; $i < sizeof($panel); $i++) {
@@ -149,6 +155,12 @@ class CliService {
$this->display = new ProgressBar($this->output);
$this->display->setOverwrite(true);
+
+ $keys = array_keys($initVar);
+ foreach ($keys as $key) {
+ $this->display->setMessage($initVar[$key], $key);
+ }
+
$this->display->clear();
$this->refreshDisplay();
@@ -157,6 +169,10 @@ class CliService {
public function refreshDisplay() {
+ if ($this->display === null) {
+ return;
+ }
+
$format = [];
foreach ($this->displayedPanel as $displayedPanel) {
$panel = $this->panels[$displayedPanel['id']];
@@ -165,14 +181,42 @@ class CliService {
}
}
-// $this->display->setMessage('<info>toto</info>');
-// $progress->setMessage('', 'jvm');
-// $progress->setMessage('', 'duration');
$this->display->setFormat(implode("\n", $format) . "\n");
+ $this->refreshInfo();
$this->display->start();
}
-// '%job:1s%%message:-40s%%current:6s%/%max:6s% [%bar%] %percent:3s%% \n %duration% %infos:-12s% %jvm:-30s% '
+ public function refreshInfo() {
+ if ($this->runner->isPauseRunning()) {
+ $this->display->setMessage('(paused)', '_paused');
+ } else {
+ $this->display->setMessage('', '_paused');
+ }
+ }
+
+ /**
+ * @param array $info
+ */
+ public function onInfoUpdated($info) {
+ if ($this->display === null) {
+ return;
+ }
+
+ $this->refreshInfo();
+ $keys = array_keys($info);
+ foreach ($keys as $k) {
+ if ($info[$k] === 'ok') {
+ $this->display->setMessage('<info>ok</info>', $k . 'Colored');
+ }
+ if ($info[$k] === 'fail') {
+ $this->display->setMessage('<error>failed</error>', $k . 'Colored');
+ }
+
+ $this->display->setMessage($info[$k], $k);
+ }
+
+ $this->display->display();
+ }
}
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index f34ad63..26866fe 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -94,17 +94,41 @@ class IndexService {
/**
- * @param $action
+ * @param string $action
+ * @param bool $force
*
* @throws InterruptException
* @throws TickDoesNotExistException
*/
- private function updateRunner($action) {
+ private function updateRunnerAction($action, $force = false) {
if ($this->runner === null) {
return;
}
- $this->runner->update($action);
+ $this->runner->updateAction($action, $force);
+ }
+
+ /**
+ * @param string $info
+ * @param string $value
+ */
+ private function updateRunnerInfo($info, $value) {
+ if ($this->runner === null) {
+ return;
+ }
+
+ $this->runner->setInfo($info, $value);
+ }
+
+ /**
+ * @param array $data
+ */
+ private function updateRunnerInfoArray($data) {
+ if ($this->runner === null) {
+ return;
+ }
+
+ $this->runner->setInfoArray($data);
}
@@ -121,7 +145,15 @@ class IndexService {
public function indexProviderContentFromUser(
IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $userId, $options
) {
- $this->updateRunner('generateIndex' . $provider->getName());
+ $this->updateRunnerAction('generateIndex' . $provider->getName());
+ $this->updateRunnerInfoArray(
+ [
+ 'userId' => $userId,
+ 'providerId' => $provider->getId(),
+ 'providerName' => $provider->getName()
+ ]
+ );
+
$documents = $provider->generateIndexableDocuments($userId);
//$maxSize = sizeof($documents);
@@ -147,7 +179,7 @@ class IndexService {
$currIndex = $this->getProviderIndexFromProvider($provider);
$result = [];
foreach ($documents as $document) {
- $this->updateRunner('compareWithCurrentIndex');
+ $this->updateRunnerAction('compareWithCurrentIndex');
$index = $currIndex->getIndex($document->getId());
if ($index === null) {
@@ -219,7 +251,7 @@ class IndexService {
$max = sizeof($documents);
for ($i = 0; $i < $max; $i++) {
- $this->updateRunner('indexChunk');
+ $this->updateRunnerAction('indexChunk', true);
try {
$chunk = array_splice($documents, 0, $chunkSize);
$this->indexChunk($platform, $provider, $chunk);
@@ -234,6 +266,8 @@ class IndexService {
throw $e;
}
}
+
+ $this->updateRunnerAction('indexChunk', true);
}