2017-05-06 19:39:39 +02:00
|
|
|
<?php
|
|
|
|
|
2018-12-03 00:59:21 +01:00
|
|
|
use Shaarli\FileUtils;
|
2018-12-02 23:24:58 +01:00
|
|
|
use Shaarli\History;
|
|
|
|
|
2017-05-06 19:39:39 +02:00
|
|
|
/**
|
|
|
|
* Populates a reference history
|
|
|
|
*/
|
|
|
|
class ReferenceHistory
|
|
|
|
{
|
|
|
|
private $count;
|
|
|
|
|
|
|
|
private $history = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the test DB with reference data
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->addEntry(
|
2017-05-07 16:56:20 +02:00
|
|
|
History::DELETED,
|
|
|
|
DateTime::createFromFormat('Ymd_His', '20170303_121216'),
|
|
|
|
124
|
2017-05-06 19:39:39 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->addEntry(
|
2017-05-07 16:56:20 +02:00
|
|
|
History::SETTINGS,
|
|
|
|
DateTime::createFromFormat('Ymd_His', '20170302_121215')
|
2017-05-06 19:39:39 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->addEntry(
|
|
|
|
History::UPDATED,
|
|
|
|
DateTime::createFromFormat('Ymd_His', '20170301_121214'),
|
|
|
|
123
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addEntry(
|
2017-05-07 16:56:20 +02:00
|
|
|
History::CREATED,
|
|
|
|
DateTime::createFromFormat('Ymd_His', '20170201_121214'),
|
|
|
|
124
|
2017-05-06 19:39:39 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->addEntry(
|
2017-05-07 16:56:20 +02:00
|
|
|
History::CREATED,
|
|
|
|
DateTime::createFromFormat('Ymd_His', '20170101_121212'),
|
|
|
|
123
|
2017-05-06 19:39:39 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new history entry
|
|
|
|
*
|
|
|
|
* @param string $event Event identifier
|
|
|
|
* @param DateTime $datetime creation date
|
|
|
|
* @param int $id optional: related link ID
|
|
|
|
*/
|
|
|
|
protected function addEntry($event, $datetime, $id = null)
|
|
|
|
{
|
|
|
|
$link = [
|
|
|
|
'event' => $event,
|
|
|
|
'datetime' => $datetime,
|
|
|
|
'id' => $id,
|
|
|
|
];
|
|
|
|
$this->history[] = $link;
|
|
|
|
$this->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes data to the datastore
|
|
|
|
*
|
|
|
|
* @param string $filename write history content to.
|
|
|
|
*/
|
|
|
|
public function write($filename)
|
|
|
|
{
|
|
|
|
FileUtils::writeFlatDB($filename, $this->history);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of links in the reference data
|
|
|
|
*/
|
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return $this->count;
|
|
|
|
}
|
|
|
|
}
|