/** * 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); } }
/** * Logs error messages. * * Events: * * breadcrumbs:beforeLogging * * breadcrumbs:afterLogging * * @param \Exception $e */ protected function log(\Exception $e) { $eventsManager = $this->getEventsManager(); if ($eventsManager) { $eventsManager->fire('breadcrumbs:beforeLogging', $this, [$e]); } if ($this->logger) { $this->logger->error($e->getMessage()); } else { error_log($e->getMessage()); } if ($eventsManager) { $eventsManager->fire('breadcrumbs:afterLogging', $this, [$e]); } }
/** * 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; }
/** * Report the uncaught exception (default implementation). * * @param Phalcon\Logger\AdapterInterface $logger * @param \Exception $exception * @return void */ public function report(Logger $logger, Exception $exception) { $logger->error($exception->getMessage() . ': ' . $exception->getTraceAsString()); }