Depot init
This commit is contained in:
117
depot_installer_script.php
Normal file
117
depot_installer_script.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
use Joomla\CMS\Log\Log;
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class DepotInstallerScript
|
||||
{
|
||||
/**
|
||||
* The Depot version we are updating from
|
||||
*/
|
||||
protected $fromVersion = null;
|
||||
|
||||
/**
|
||||
* Callback for collectiong errors. Like function(string $context, \Throwable $error){};
|
||||
*
|
||||
* @var callable
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
protected $errorCollector;
|
||||
|
||||
/**
|
||||
* Set the callback for collecting errors.
|
||||
*
|
||||
* @param callable $callback The callback Like function(string $context, \Throwable $error){};
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function setErrorCollector(callable $callback) {
|
||||
$this->errorCollector = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect errors.
|
||||
*
|
||||
* @param string $context A context/place where error happened
|
||||
* @param \Throwable $error The error that occurred
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
protected function collectError(string $context, \Throwable $error) {
|
||||
// The errorCollector are required
|
||||
// However when someone already running the script manually the code may fail.
|
||||
if ($this->errorCollector) {
|
||||
call_user_func($this->errorCollector, $context, $error);
|
||||
} else {
|
||||
Log::add($error->getMessage(), Log::ERROR, 'Update');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to act prior to installation process begins
|
||||
*
|
||||
* @param string $action Which action is happening (install|uninstall|discover_install|update)
|
||||
* @param Installer $installer The class calling this method
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function preflight($action, $installer) {
|
||||
if ($action === 'update') {
|
||||
// Get the version we are updating from
|
||||
if (!empty($installer->extension->manifest_cache)) {
|
||||
$manifestValues = json_decode($installer->extension->manifest_cache, true);
|
||||
|
||||
if (array_key_exists('version', $manifestValues)) {
|
||||
$this->fromVersion = $manifestValues['version'];
|
||||
|
||||
Log::add(Text::_('COM_DEPOT_PREFLIGHT_FROM_VERSION'), Log::INFO, 'Update');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to update Depot
|
||||
*
|
||||
* @param Installer $installer The class calling this method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update($installer) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after any type of action
|
||||
*
|
||||
* @param string $action Which action is happening (install|uninstall|discover_install|update)
|
||||
* @param Installer $installer The class calling this method
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function postflight($action, $installer)
|
||||
{
|
||||
if ($action !== 'update') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($this->fromVersion) || version_compare($this->fromVersion, '0.0.1', 'ge')) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user