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": [ "packages": [
{ {
"name": "articapfms/update_manager_client", "name": "articapfms/update_manager_client",
"version": "v1.0.1", "version": "v1.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/articaST/updatemanager.git", "url": "https://github.com/articaST/updatemanager.git",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3" "reference": "f9dfed615a571311f54370a2e6a045ed0559b95b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/c3206367fc362d823835cb2f72363db78901a2e3", "url": "https://api.github.com/repos/articaST/updatemanager/zipball/f9dfed615a571311f54370a2e6a045ed0559b95b",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3", "reference": "f9dfed615a571311f54370a2e6a045ed0559b95b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -46,9 +46,9 @@
"description": "Artica PFMS Update Manager Client", "description": "Artica PFMS Update Manager Client",
"support": { "support": {
"issues": "https://github.com/articaST/updatemanager/issues", "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", "name": "doctrine/lexer",

View File

@ -91,4 +91,5 @@ deploy_packagist:
needs: needs:
- job: test - job: test
script: 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; private $updates;
/**
* Available LTS updates.
*
* @var array
*/
private $updatesLTS;
/** /**
* Where is installed the product files. * Where is installed the product files.
* *
@ -280,6 +287,20 @@ class Client
*/ */
private $lockfile; 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. * Constructor.
@ -303,6 +324,11 @@ class Client
* - password * - password
* - host * - host
* - port * - 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 * (*) mandatory
* (**) Optionally, set full url instead host-port-endpoint. * (**) Optionally, set full url instead host-port-endpoint.
@ -323,6 +349,7 @@ class Client
$this->registrationCode = ''; $this->registrationCode = '';
$this->license = ''; $this->license = '';
$this->updates = []; $this->updates = [];
$this->updatesLTS = [];
$this->dbh = null; $this->dbh = null;
$this->dbhHistory = null; $this->dbhHistory = null;
$this->MR = 0; $this->MR = 0;
@ -338,6 +365,8 @@ class Client
$this->timezone = null; $this->timezone = null;
$this->propagateUpdates = false; $this->propagateUpdates = false;
$this->offline = false; $this->offline = false;
$this->lts = false;
$this->postUpdateFN = null;
if (is_array($settings) === true) { if (is_array($settings) === true) {
if (isset($settings['homedir']) === true) { if (isset($settings['homedir']) === true) {
@ -419,6 +448,16 @@ class Client
$this->MR = $settings['MR']; $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) { if (isset($settings['endpoint']) === true) {
$this->endPoint = $settings['endpoint']; $this->endPoint = $settings['endpoint'];
if (substr( if (substr(
@ -745,6 +784,7 @@ class Client
'limit_count' => $this->limitCount, 'limit_count' => $this->limitCount,
'language' => $this->language, 'language' => $this->language,
'timezone' => $this->timezone, 'timezone' => $this->timezone,
'lts' => $this->lts,
// Retrocompatibility token. // Retrocompatibility token.
'version' => $pandora_version, 'version' => $pandora_version,
'puid' => $this->registrationCode, '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. * Retrieves a list of updates available in target UMS.
* *
@ -824,6 +901,7 @@ class Client
* 'version' => Version id. * 'version' => Version id.
* 'file_name' => File name. * 'file_name' => File name.
* 'description' => description. * 'description' => description.
* 'lts' => Lts update or not.
* ] * ]
* ]; * ];
*/ */
@ -831,34 +909,57 @@ class Client
{ {
$this->nextUpdate = null; $this->nextUpdate = null;
if (empty($this->updates) === true) { 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) { if (is_array($rc) !== true) {
// Propagate last error from request. // Propagate last error from request.
return null; return null;
} }
// Translate respone. // Translate response.
$this->updates = array_reduce( $updates = $this->translateUpdatePackages($rc, true);
$rc, $lts_updates = $updates;
$this->updatesLTS = array_reduce(
$updates,
function ($carry, $item) { function ($carry, $item) {
$matches = []; $carry[$item['version']] = 1;
if (is_array($item) !== true
&& preg_match('/([\d\.\d]+?)\.tar/', $item, $matches) > 0
) {
$carry[] = [
'version' => $matches[1],
'file_name' => $item,
'description' => '',
];
} else {
$carry[] = $item;
}
return $carry; 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. // Allows 'notify' follow current operation.
@ -871,6 +972,10 @@ class Client
} }
} }
if ($this->lts === true) {
return $lts_updates;
}
return $this->updates; return $this->updates;
} }
@ -1441,8 +1546,8 @@ class Client
$er = error_reporting(); $er = error_reporting();
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
set_error_handler( set_error_handler(
function ($errno, $errstr) { function ($errno, $errstr, $at, $line) {
throw new \Exception($errstr, $errno); throw new \Exception($errstr.' '.$at.':'.$line, $errno);
}, },
(E_ALL ^ E_NOTICE) (E_ALL ^ E_NOTICE)
); );
@ -1457,7 +1562,10 @@ class Client
// 1. List updates and get next one. // 1. List updates and get next one.
$this->notify(0, 'Retrieving updates.'); $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; $nextUpdate = null;
if (is_array($updates) === true) { if (is_array($updates) === true) {
@ -1779,21 +1887,80 @@ class Client
$this->updateLocalDatabase(); $this->updateLocalDatabase();
} }
if (is_callable($this->postUpdateFN) === true) {
call_user_func(
$this->postUpdateFN,
$this->currentPackage,
'console'
);
}
$this->unlock(); $this->unlock();
return true; 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. * @return string Last version reached.
*/ */
public function updateLastVersion():string public function updateLastVersion(?string $target_version=null):string
{ {
$this->percentage = 0; $this->percentage = 0;
$this->listUpdates(); $this->listUpdates();
$total_updates = count($this->updates);
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) { if ($total_updates > 0) {
$pct = (90 / $total_updates); $pct = (90 / $total_updates);
@ -1806,6 +1973,11 @@ class Client
break; break;
} }
if ($this->nextUpdate === $target_version) {
// Reached end.
$rc = null;
}
// If rc is null, latest version available is applied. // If rc is null, latest version available is applied.
if ($rc !== null) { if ($rc !== null) {
$this->percentage += $pct; $this->percentage += $pct;
@ -2052,6 +2224,15 @@ class Client
// Success. // Success.
$this->notify(100, 'Server update scheduled.'); $this->notify(100, 'Server update scheduled.');
$this->lastError = null; $this->lastError = null;
if (is_callable($this->postUpdateFN) === true) {
call_user_func(
$this->postUpdateFN,
$this->currentPackage,
'server'
);
}
return true; return true;
} }

View File

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

View File

@ -172,7 +172,7 @@ div#box_online * {
} }
#box_online .content { #box_online .content {
max-width: 60%; max-width: 50%;
} }
.update_popup { .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": [ "packages": [
{ {
"name": "articapfms/update_manager_client", "name": "articapfms/update_manager_client",
"version": "v1.0.1", "version": "v1.0.2",
"version_normalized": "1.0.1.0", "version_normalized": "1.0.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/articaST/updatemanager.git", "url": "https://github.com/articaST/updatemanager.git",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3" "reference": "f9dfed615a571311f54370a2e6a045ed0559b95b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/articaST/updatemanager/zipball/c3206367fc362d823835cb2f72363db78901a2e3", "url": "https://api.github.com/repos/articaST/updatemanager/zipball/f9dfed615a571311f54370a2e6a045ed0559b95b",
"reference": "c3206367fc362d823835cb2f72363db78901a2e3", "reference": "f9dfed615a571311f54370a2e6a045ed0559b95b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -22,7 +22,7 @@
"phpunit/phpunit": "^8.5.14", "phpunit/phpunit": "^8.5.14",
"squizlabs/php_codesniffer": "^3.6" "squizlabs/php_codesniffer": "^3.6"
}, },
"time": "2022-03-28T10:16:13+00:00", "time": "2022-03-29T17:09:05+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -43,7 +43,7 @@
"description": "Artica PFMS Update Manager Client", "description": "Artica PFMS Update Manager Client",
"support": { "support": {
"issues": "https://github.com/articaST/updatemanager/issues", "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" "install-path": "../articapfms/update_manager_client"
}, },

View File

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