Vendor files update (unneeded in a while)

This commit is contained in:
fbsanchez 2022-03-29 19:22:26 +02:00
parent dd798d6f52
commit dd1768535d
8 changed files with 247 additions and 125 deletions

View File

@ -8,16 +8,16 @@
"packages": [
{
"name": "articapfms/update_manager_client",
"version": "v1.0.1",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/articaST/updatemanager.git",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3"
"reference": "f9dfed615a571311f54370a2e6a045ed0559b95b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/c3206367fc362d823835cb2f72363db78901a2e3",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/f9dfed615a571311f54370a2e6a045ed0559b95b",
"reference": "f9dfed615a571311f54370a2e6a045ed0559b95b",
"shasum": ""
},
"require": {
@ -46,9 +46,9 @@
"description": "Artica PFMS Update Manager Client",
"support": {
"issues": "https://github.com/articaST/updatemanager/issues",
"source": "https://github.com/articaST/updatemanager/tree/v1.0.1"
"source": "https://github.com/articaST/updatemanager/tree/v1.0.2"
},
"time": "2022-03-28T10:16:13+00:00"
"time": "2022-03-29T17:09:05+00:00"
},
{
"name": "doctrine/lexer",

View File

@ -91,4 +91,5 @@ deploy_packagist:
needs:
- job: test
script:
- curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=articast&apiToken=$PACKAGIST_API_TOKEN" -d'{"repository":{"url":"$PACKAGIST_PROJECT_URL"}}'
- echo "Updating $PACKAGIST_PROJECT_URL"
- curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=articast&apiToken=$PACKAGIST_API_TOKEN&autoUpdated=1" -d"{\"repository\":{\"url\":\"$PACKAGIST_PROJECT_URL\"}}"

View File

@ -189,6 +189,13 @@ class Client
*/
private $updates;
/**
* Available LTS updates.
*
* @var array
*/
private $updatesLTS;
/**
* Where is installed the product files.
*
@ -280,6 +287,20 @@ class Client
*/
private $lockfile;
/**
* Search for long term support updates only.
*
* @var boolean
*/
private $lts;
/**
* Function to be called after each package upgrade.
*
* @var callable|null
*/
private $postUpdateFN;
/**
* Constructor.
@ -303,6 +324,11 @@ class Client
* - password
* - host
* - port
* - lts
* - postUpdateFN: function to be called after each upgrade.
* will receive 2 parameters, version and string
* containing 'server' if server upgrade or 'console'
* if console upgrade was performed.
*
* (*) mandatory
* (**) Optionally, set full url instead host-port-endpoint.
@ -323,6 +349,7 @@ class Client
$this->registrationCode = '';
$this->license = '';
$this->updates = [];
$this->updatesLTS = [];
$this->dbh = null;
$this->dbhHistory = null;
$this->MR = 0;
@ -338,6 +365,8 @@ class Client
$this->timezone = null;
$this->propagateUpdates = false;
$this->offline = false;
$this->lts = false;
$this->postUpdateFN = null;
if (is_array($settings) === true) {
if (isset($settings['homedir']) === true) {
@ -419,6 +448,16 @@ class Client
$this->MR = $settings['MR'];
}
if (isset($settings['lts']) === true) {
$this->lts = $settings['lts'];
}
if (isset($settings['on_update']) === true
&& is_callable($settings['on_update']) === true
) {
$this->postUpdateFN = $settings['on_update'];
}
if (isset($settings['endpoint']) === true) {
$this->endPoint = $settings['endpoint'];
if (substr(
@ -745,6 +784,7 @@ class Client
'limit_count' => $this->limitCount,
'language' => $this->language,
'timezone' => $this->timezone,
'lts' => $this->lts,
// Retrocompatibility token.
'version' => $pandora_version,
'puid' => $this->registrationCode,
@ -815,6 +855,43 @@ class Client
}
/**
* Translate Open and Enterprise oum updates into rigth format.
*
* @param array $updates Raw updates retrieved from UMS.
* @param boolean $lts LTS updates or generic.
*
* @return array Translated updates.
*/
private function translateUpdatePackages(array $updates, bool $lts)
{
$lts_ones = $this->updatesLTS;
return array_reduce(
$updates,
function ($carry, $item) use ($lts, $lts_ones) {
if (is_array($item) !== true
&& preg_match('/([\d\.\d]+?)\.tar/', $item, $matches) > 0
) {
$carry[] = [
'version' => $matches[1],
'file_name' => $item,
'description' => '',
'lts' => ($lts === true) ? $lts : isset($lts_ones[$matches[1]]),
];
} else {
$carry[] = array_merge(
$item,
['lts' => ($lts === true) ? $lts : isset($lts_ones[$item['version']])]
);
}
return $carry;
},
[]
);
}
/**
* Retrieves a list of updates available in target UMS.
*
@ -824,6 +901,7 @@ class Client
* 'version' => Version id.
* 'file_name' => File name.
* 'description' => description.
* 'lts' => Lts update or not.
* ]
* ];
*/
@ -831,34 +909,57 @@ class Client
{
$this->nextUpdate = null;
if (empty($this->updates) === true) {
$rc = $this->post([ 'action' => 'newer_packages' ]);
$rc = $this->post(
[
'action' => 'newer_packages',
'arguments' => ['lts' => true],
]
);
if (is_array($rc) !== true) {
// Propagate last error from request.
return null;
}
// Translate respone.
$this->updates = array_reduce(
$rc,
// Translate response.
$updates = $this->translateUpdatePackages($rc, true);
$lts_updates = $updates;
$this->updatesLTS = array_reduce(
$updates,
function ($carry, $item) {
$matches = [];
if (is_array($item) !== true
&& preg_match('/([\d\.\d]+?)\.tar/', $item, $matches) > 0
) {
$carry[] = [
'version' => $matches[1],
'file_name' => $item,
'description' => '',
];
} else {
$carry[] = $item;
}
$carry[$item['version']] = 1;
return $carry;
},
[]
);
$rc = $this->post(
[
'action' => 'newer_packages',
'arguments' => ['lts' => false],
]
);
if (is_array($rc) !== true) {
// Propagate last error from request.
return null;
}
// Translate response.
$all_updates = $this->translateUpdatePackages($rc, false);
$this->updates = $all_updates;
} else {
$lts_updates = array_filter(
$this->updates,
function ($item) {
if ($item['lts'] === true) {
return true;
}
return false;
}
);
}
// Allows 'notify' follow current operation.
@ -871,6 +972,10 @@ class Client
}
}
if ($this->lts === true) {
return $lts_updates;
}
return $this->updates;
}
@ -1441,8 +1546,8 @@ class Client
$er = error_reporting();
error_reporting(E_ALL ^ E_NOTICE);
set_error_handler(
function ($errno, $errstr) {
throw new \Exception($errstr, $errno);
function ($errno, $errstr, $at, $line) {
throw new \Exception($errstr.' '.$at.':'.$line, $errno);
},
(E_ALL ^ E_NOTICE)
);
@ -1457,7 +1562,10 @@ class Client
// 1. List updates and get next one.
$this->notify(0, 'Retrieving updates.');
$updates = $this->listUpdates();
// Reload if needed.
$this->listUpdates();
// Work over all upgrades not LTS only.
$updates = $this->updates;
$nextUpdate = null;
if (is_array($updates) === true) {
@ -1779,21 +1887,80 @@ class Client
$this->updateLocalDatabase();
}
if (is_callable($this->postUpdateFN) === true) {
call_user_func(
$this->postUpdateFN,
$this->currentPackage,
'console'
);
}
$this->unlock();
return true;
}
/**
* Update product to latest version available.
* Return next LTS version available.
*
* @return string|null Next version string or null if no version present.
*/
public function getNextLTSVersion():?string
{
$lts = $this->listUpdates();
if ($lts === null) {
return null;
}
$target = array_shift($lts);
return $target['version'];
}
/**
* Return latest LTS version available.
*
* @return string|null Latest version string or null if no version present.
*/
public function getLastLTSVersion():?string
{
$lts = $this->listUpdates();
if ($lts === null) {
return null;
}
$target = array_pop($lts);
return $target['version'];
}
/**
* Update product to latest version available or target if specified.
*
* @param string|null $target_version Target version if needed.
*
* @return string Last version reached.
*/
public function updateLastVersion():string
public function updateLastVersion(?string $target_version=null):string
{
$this->percentage = 0;
$this->listUpdates();
if ($target_version !== null) {
// Update to target version.
$total_updates = 0;
foreach ($this->updates as $update) {
$total_updates++;
if ($update['version'] === $target_version) {
break;
}
}
} else {
// All updates.
$total_updates = count($this->updates);
}
if ($total_updates > 0) {
$pct = (90 / $total_updates);
@ -1806,6 +1973,11 @@ class Client
break;
}
if ($this->nextUpdate === $target_version) {
// Reached end.
$rc = null;
}
// If rc is null, latest version available is applied.
if ($rc !== null) {
$this->percentage += $pct;
@ -2052,6 +2224,15 @@ class Client
// Success.
$this->notify(100, 'Server update scheduled.');
$this->lastError = null;
if (is_callable($this->postUpdateFN) === true) {
call_user_func(
$this->postUpdateFN,
$this->currentPackage,
'server'
);
}
return true;
}

View File

@ -100,6 +100,13 @@ class Manager
*/
private $composer = false;
/**
* Working in LTS mode.
*
* @var boolean
*/
private $lts = false;
/**
* Undocumented function
@ -125,6 +132,7 @@ class Manager
$this->ajaxUrl = '#';
$this->mode = self::MODE_ONLINE;
$this->composer = $composer;
$this->lts = false;
if (empty($public_url) === false) {
$this->publicUrl = $public_url;
@ -165,6 +173,10 @@ class Manager
$settings['offline'] = true;
}
if (isset($settings['lts']) === true) {
$this->lts = $settings['lts'];
}
if (isset($settings['allowOfflinePatches']) === true) {
$this->allowOfflinePatches = (bool) $settings['allowOfflinePatches'];
}
@ -355,7 +367,13 @@ class Manager
// Execute target action.
switch ($_REQUEST['action']) {
case 'nextUpdate':
if ($this->lts === true) {
$next_version = $this->umc->getNextLTSVersion();
$result = $this->umc->updateLastVersion($next_version);
} else {
$result = $this->umc->updateNextVersion();
}
if ($result !== true) {
$error = $this->umc->getLastError();
}
@ -368,9 +386,11 @@ class Manager
break;
case 'latestUpdate':
if ($this->lts === true) {
$latest_version = $this->umc->getLastLTSVersion();
$result = $this->umc->updateLastVersion($latest_version);
} else {
$result = $this->umc->updateLastVersion();
if ($result !== true) {
$error = $this->umc->getLastError();
}
$return = [

View File

@ -172,7 +172,7 @@ div#box_online * {
}
#box_online .content {
max-width: 60%;
max-width: 50%;
}
.update_popup {

View File

@ -1,80 +0,0 @@
<?php
if ($argv === null) {
header('Location: /');
exit(0);
}
// UMC dependencies.
require_once __DIR__.'/vendor/autoload.php';
chdir(__DIR__.'/../../');
$cnf_file = 'include/config.php';
if (file_exists($cnf_file) === false) {
exit(0);
}
ini_set('display_errors', 1);
require_once $cnf_file;
// PandoraFMS dependencies.
require_once __DIR__.'/vendor/autoload.php';
use PandoraFMS\Core\Config;
use PandoraFMS\Core\DBMaintainer;
global $config;
error_reporting(E_ALL ^ E_NOTICE);
try {
$historical_dbh = null;
if (isset($config['history_db_enabled']) === true
&& (bool) $config['history_db_enabled'] === true
) {
$dbm = new DBMaintainer(
[
'host' => $config['history_db_host'],
'port' => $config['history_db_port'],
'name' => $config['history_db_name'],
'user' => $config['history_db_user'],
'pass' => $config['history_db_pass'],
]
);
$historical_dbh = $dbm->getDBH();
}
$current_mr = db_get_value('value', 'tconfig', 'token', 'MR');
echo 'MR: '.$current_mr."\n";
if ((bool) $historical_dbh === true) {
echo 'current historyDB MR: '.Config::get('MR', 'unknown', true)."\n";
}
$umc = new UpdateManager\Client(
[
'homedir' => $config['homedir'],
'dbconnection' => $config['dbconnection'],
'historydb' => $historical_dbh,
'MR' => (int) $current_mr,
]
);
if ($umc->applyAllMRPending() !== true) {
echo ($umc->getMR() + 1).': '.$umc->getLastError();
}
$current_mr = $umc->getMR();
echo 'current MR: '.$current_mr."\n";
if ((bool) $historical_dbh === true) {
echo 'current historyDB MR: '.Config::get('MR', 'unknown', true)."\n";
}
} catch (Exception $e) {
echo $e->getMessage().' in '.$e->getFile().':'.$e->getLine()."\n";
}

View File

@ -2,17 +2,17 @@
"packages": [
{
"name": "articapfms/update_manager_client",
"version": "v1.0.1",
"version_normalized": "1.0.1.0",
"version": "v1.0.2",
"version_normalized": "1.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/articaST/updatemanager.git",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3"
"reference": "f9dfed615a571311f54370a2e6a045ed0559b95b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/c3206367fc362d823835cb2f72363db78901a2e3",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/f9dfed615a571311f54370a2e6a045ed0559b95b",
"reference": "f9dfed615a571311f54370a2e6a045ed0559b95b",
"shasum": ""
},
"require": {
@ -22,7 +22,7 @@
"phpunit/phpunit": "^8.5.14",
"squizlabs/php_codesniffer": "^3.6"
},
"time": "2022-03-28T10:16:13+00:00",
"time": "2022-03-29T17:09:05+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -43,7 +43,7 @@
"description": "Artica PFMS Update Manager Client",
"support": {
"issues": "https://github.com/articaST/updatemanager/issues",
"source": "https://github.com/articaST/updatemanager/tree/v1.0.1"
"source": "https://github.com/articaST/updatemanager/tree/v1.0.2"
},
"install-path": "../articapfms/update_manager_client"
},

View File

@ -11,12 +11,12 @@
),
'versions' => array(
'articapfms/update_manager_client' => array(
'pretty_version' => 'v1.0.1',
'version' => '1.0.1.0',
'pretty_version' => 'v1.0.2',
'version' => '1.0.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../articapfms/update_manager_client',
'aliases' => array(),
'reference' => 'c3206367fc362d823835cb2f72363db78901a2e3',
'reference' => 'f9dfed615a571311f54370a2e6a045ed0559b95b',
'dev_requirement' => false,
),
'doctrine/lexer' => array(