New feature: Branch name for software products

This commit is contained in:
Steffen Lange 2020-04-01 17:25:40 +02:00
parent dd3be30e56
commit 3d037ec2b3
5 changed files with 13 additions and 6 deletions

View file

@ -45,16 +45,16 @@ class Database {
} }
function find(string $id) : PatchObject { function find(string $id) : PatchObject {
foreach ($this->data as $obj) { foreach ($this->data as $obj) {
if (strcmp($obj->GetId(), $id) == 0) { if (strcmp($obj->getId(), $id) == 0) {
return $obj; return $obj;
} }
} }
return new PatchObject(); return new PatchObject();
} }
function addOrUpdate(PatchObject $patch) { function addOrUpdate(PatchObject $patch) {
$patch->SetTimestamp($this->time); $patch->setTimestamp($this->time);
foreach ($this->data as &$obj) { foreach ($this->data as &$obj) {
if (strcmp($obj->GetId(), $patch->GetId()) == 0) { if (strcmp($obj->getId(), $patch->getId()) == 0) {
$obj = $patch; $obj = $patch;
return; return;
} }

View file

@ -34,7 +34,7 @@ abstract class PatchBase {
} }
protected function parse(string $re) : bool { protected function parse(string $re) : bool {
if ($str = $this->regex_str($re)) { if ($str = $this->regex_str($re)) {
$this->patch->SetVersion($str); $this->patch->setVersion($str);
return true; return true;
} }
return false; return false;
@ -42,7 +42,7 @@ abstract class PatchBase {
protected function parse_json(string $key) : bool { protected function parse_json(string $key) : bool {
$flat = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data))); $flat = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data)));
if (!empty($flat[$key])) { if (!empty($flat[$key])) {
$this->patch->SetVersion($flat[$key]); $this->patch->setVersion($flat[$key]);
return true; return true;
} }
return false; return false;

View file

@ -13,6 +13,7 @@ foreach (new \DirectoryIterator(__DIR__ . '/modules') as $file) {
} }
} }
} }
shuffle($list);
$db = new Database(__DIR__ . '/db.json'); $db = new Database(__DIR__ . '/db.json');
echo 'Time: ' . date('c', $db->time()) . PHP_EOL; echo 'Time: ' . date('c', $db->time()) . PHP_EOL;

View file

@ -32,6 +32,9 @@ class PatchObject {
function getBranch() : string { function getBranch() : string {
return $this->branch; return $this->branch;
} }
function setBranch(string $branch) {
$this->branch = $branch;
}
function getVersion() : string { function getVersion() : string {
return $this->version; return $this->version;
} }

View file

@ -31,7 +31,10 @@ $twitter = new Twitter($TwitterConsumerKey, $TwitterConsumerSecret, $TwitterAcce
for ($i = 0; $i < $db->count(); $i++) { for ($i = 0; $i < $db->count(); $i++) {
$patch = $db->get($i); $patch = $db->get($i);
if ($last < $patch->getTimestamp()) { if ($last < $patch->getTimestamp()) {
$s = $patch->getVendor() . ' released #' . $patch->getProduct() . ' version ' . $patch->getVersion() . '. ' . $patch->getURL(); $s = $patch->getVendor() . ' released #' . $patch->getProduct();
if (!empty($patch->getBranch()))
$s .= ' ' . $patch->getBranch();
$s .= ' version ' . $patch->getVersion() . '. ' . $patch->getURL();
try { try {
$twitter->send($s); $twitter->send($s);
} catch (DG\Twitter\Exception $e) { } catch (DG\Twitter\Exception $e) {