/** * Indexes all posts in the forum in ES */ public function indexAll() { $deleteParams = ['index' => $this->config->get('index', 'phosphorum')]; try { $this->client->indices()->delete($deleteParams); } catch (Missing404Exception $e) { $this->logger->info('The index does not exist yet. Skip deleting...'); } catch (\Exception $e) { $this->logger->error("Indexer: {$e->getMessage()}. {$e->getFile()}:{$e->getLine()}"); } foreach (Posts::find('deleted != ' . Posts::IS_DELETED) as $post) { $this->doIndex($post); } }
/** * Execute command in our command executor * @param string external command * */ private function executeShell($command, &$stdout = null, &$stderr = null) { $this->logger->info("Execute command: `{$command}`"); $proc = proc_open($command, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); // Find stdout (standar output) from its command $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); // Find stderr (standar error output) from its command $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); $exitCode = proc_close($proc); // Write stdout/stderr into cron service log file $this->logger->info("Stdout `{$command}`: {$stdout}"); $this->logger->error("Stderr `{$command}`: {$stderr}"); $this->logger->info("Exitcode {$exitCode}"); return $exitCode; }