X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FHistory.php;h=8074a0172c634912adf507bcd2236d8419cffe81;hb=bdc5152d486ca75372c271f94623b248bc127800;hp=f93b03568235c1f71ecc7d9d86b21e0a56fab34b;hpb=77de24876ff542e3770aa2845e993c58f87e37df;p=github%2Fshaarli%2FShaarli.git diff --git a/application/History.php b/application/History.php index f93b0356..8074a017 100644 --- a/application/History.php +++ b/application/History.php @@ -1,4 +1,9 @@ addEvent(self::SETTINGS); } + /** + * Add Event: bulk import. + * + * Note: we don't store links add/update one by one since it can have a huge impact on performances. + */ + public function importLinks() + { + $this->addEvent(self::IMPORT); + } + /** * Save a new event and write it in the history file. * * @param string $status Event key, should be defined as constant. - * @param mixed $id Event item identifier (e.g. link ID). + * @param mixed $id Event item identifier (e.g. link ID). */ protected function addEvent($status, $id = null) { @@ -135,7 +156,7 @@ class History $item = [ 'event' => $status, - 'datetime' => (new DateTime())->format(DateTime::ATOM), + 'datetime' => new DateTime(), 'id' => $id !== null ? $id : '', ]; $this->history = array_merge([$item], $this->history); @@ -150,12 +171,12 @@ class History */ protected function check() { - if (! is_file($this->historyFilePath)) { + if (!is_file($this->historyFilePath)) { FileUtils::writeFlatDB($this->historyFilePath, []); } - if (! is_writable($this->historyFilePath)) { - throw new Exception('History file isn\'t readable or writable'); + if (!is_writable($this->historyFilePath)) { + throw new Exception(t('History file isn\'t readable or writable')); } } @@ -166,7 +187,7 @@ class History { $this->history = FileUtils::readFlatDB($this->historyFilePath, []); if ($this->history === false) { - throw new Exception('Could not parse history file'); + throw new Exception(t('Could not parse history file')); } } @@ -175,9 +196,9 @@ class History */ protected function write() { - $comparaison = new DateTime('-'. $this->retentionTime . ' seconds'); + $comparaison = new DateTime('-' . $this->retentionTime . ' seconds'); foreach ($this->history as $key => $value) { - if (DateTime::createFromFormat(DateTime::ATOM, $value['datetime']) < $comparaison) { + if ($value['datetime'] < $comparaison) { unset($this->history[$key]); } }