Skip to content
Permalink
Browse files

Added : onBeforeInjectPluginServiceProviders event

Added   : onBeforeInjectPluginRoutes event
Removed : onBeforePluginsRoute event
Removed : onAfterPluginsRoute event
Other   : CS fixes, typo
  • Loading branch information...
nuxwin committed Jun 12, 2019
1 parent 6c4dd8f commit 4de6f87684993e94dbb2c6c14f921438c92c61a9
@@ -469,7 +469,8 @@ sub _executePluginAction
action => $self->{'pluginAction'},
config => $self->{'pluginData'}->{'config'},
config_prev => ( ( $self->{'pluginAction'} =~ /^(?:change|update)$/ )
# On plugin change/update, make sure that prev config also contains any new parameter
# On plugin change/update, make sure that prev config also
# contains new parameters (left precedence, default behavior of merge())
? merge( $self->{'pluginData'}->{'config_prev'}, $self->{'pluginData'}->{'config'} )
: $self->{'pluginData'}->{'config_prev'} ),
eventManager => $self->{'events'},
@@ -343,9 +343,9 @@ function i18n_changeDefaultLanguage()
/**
* Add translations
*
* This function allow any plugin to add its translations.
* This function allow any plugin to add its translation resources.
*
* @param string $dirPath Absolute path to the translations root directory
* @param string $dir Absolute path to the translations root directory
* @param string $type Translations type (array, Csv, Gettext, Ini, Qt, Tbx, Tmx, Xliff, XmlTm)
* @param string $tag Tag which is used for caching (eg. plugin name)
* @param string|null $scan If set to NULL, no scanning of the directory structure will be done. If set to
@@ -355,15 +355,20 @@ function i18n_changeDefaultLanguage()
* @throws Zend_Exception
* @throws Zend_Translate_Exception
*/
function l10n_addTranslations($dirPath, $type = 'Array', $tag = 'iMSCP_Translate', $scan = Translator::LOCALE_FILENAME)
function l10n_addTranslations(
$dir,
$type = 'Array',
$tag = 'iMSCP_Translate',
$scan = Translator::LOCALE_FILENAME
)
{
/** @var Zend_Translate_Adapter $primaryTranslator */
$primaryTranslator = Registry::get('Zend_Translate')->getAdapter();
$locale = $primaryTranslator->getLocale();
$pluginTranslator = new Translator([
'adapter' => $type,
'content' => $dirPath,
'content' => $dir,
'scan' => $scan,
'locale' => $locale,
'disableNotices' => true,
@@ -912,6 +912,7 @@ protected function loadPlugins()
if (PHP_SAPI == 'cli') {
return;
}
$pluginManager = $this->getPluginManager();
foreach ($pluginManager->pluginGetList() as $pluginName) {
@@ -626,25 +626,24 @@ class iMSCP_Events
const onAfterDeleteCustomDNSrecord = 'onAfterDeleteCustomDNSrecord';
/**
* Event triggered before plugin routing
* Event triggered before injection of plugin service providers
*
* iMSCP_Events_Event object parameter:
* - pluginManager : iMSCP_Plugin_Manager instance
*
* @const string
*/
const onBeforePluginsRoute = 'onBeforePluginsRoute';
const onBeforeInjectPluginServiceProviders = 'onBeforeInjectPluginServiceProviders';
/**
* Event triggered after plugin routing
* Event triggered before injection of plugin routes
*
* iMSCP_Events_Event object parameter:
* - pluginManager : iMSCP_Plugin_Manager instance
* - scriptPath : Plugin action script path
*
* @const string
*/
const onAfterPluginsRoute = 'onAfterPluginsRoute';
const onBeforeInjectPluginRoutes = 'onBeforeInjectPluginRoutes';
/**
* Event triggered before plugin list update
@@ -1,4 +1,4 @@
<?php /** @noinspection ALL */
<?php
/**
* i-MSCP - internet Multi Server Control Panel
* Copyright (C) 2010-2019 by Laurent Declercq <l.declercq@nuxwin.com>
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection PhpIncludeInspection */
/**
* iMSCP_Plugin class
*
@@ -59,11 +61,11 @@ abstract class iMSCP_Plugin
/**
* Constructor
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
*/
public function __construct(iMSCP_Plugin_Manager $pluginManager)
public function __construct(iMSCP_Plugin_Manager $pm)
{
$this->pluginManager = $pluginManager;
$this->pluginManager = $pm;
$this->init();
}
@@ -90,13 +92,13 @@ public function getPluginManager()
* build: Last build of the plugin in YYYYMMDDNN format
* name: Plugin name
* desc: Plugin short description (text only)
* url: Website in which it's possible to found more information about the
* url: OPTIONAL Website URL at which it's possible to found more information about the
* plugin
* priority: OPTIONAL priority which define priority for plugin backend
* processing
*
* A plugin can provide any other info for its own needs. However, the
* following keywords are reserved for internal use:
* following fields are reserved for internal use:
*
* __nversion__ : Last available plugin version
* __installable__ : Whether or not the plugin is installable
@@ -323,7 +325,7 @@ function getInfo()
}
/**
* Allow plugin initialization
* Plugin initialization tasks
*
* This method allow to do some initialization tasks without overriding the
* constructor.
@@ -335,97 +337,96 @@ protected function init()
}
/**
* Plugin installation
* Plugin installation tasks
*
* This method is automatically called by the plugin manager when the
* plugin is being installed.
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function install(iMSCP_Plugin_Manager $pluginManager)
public function install(iMSCP_Plugin_Manager $pm)
{
}
/**
* Plugin activation
* Plugin uninstallation tasks
*
* This method is automatically called by the plugin manager when the
* plugin is being enabled (activated).
* plugin is being uninstalled.
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function enable(iMSCP_Plugin_Manager $pluginManager)
public function uninstall(iMSCP_Plugin_Manager $pm)
{
}
/**
* Plugin deactivation
* Plugin deletion tasks
*
* This method is automatically called by the plugin manager when the
* plugin is being disabled (deactivated).
* plugin is being deleted.
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function disable(iMSCP_Plugin_Manager $pluginManager)
public function delete(iMSCP_Plugin_Manager $pm)
{
}
/**
* Plugin update
* Plugin update tasks
*
* This method is automatically called by the plugin manager when
* the plugin is being updated.
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @param string $fromVersion Version from which plugin update is initiated
* @param string $toVersion Version to which plugin is updated
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function update(iMSCP_Plugin_Manager $pluginManager, $fromVersion, $toVersion)
public function update(iMSCP_Plugin_Manager $pm, $fromVersion, $toVersion)
{
}
/**
* Plugin uninstallation
* Plugin activation tasks
*
* This method is automatically called by the plugin manager when the
* plugin is being uninstalled.
* plugin is being enabled (activated).
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function uninstall(iMSCP_Plugin_Manager $pluginManager)
public function enable(iMSCP_Plugin_Manager $pm)
{
}
/**
* Plugin deletion
* Plugin deactivation tasks
*
* This method is automatically called by the plugin manager when the
* plugin is being deleted.
* plugin is being disabled (deactivated).
*
* @param iMSCP_Plugin_Manager $pluginManager
* @param iMSCP_Plugin_Manager $pm
* @return void
* @throws iMSCP_Plugin_Exception
*/
public function delete(iMSCP_Plugin_Manager $pluginManager)
public function disable(iMSCP_Plugin_Manager $pm)
{
}
/**
* Get plugin item with error status
*
* This method is called by the i-MSCP debugger.
*
* Note: *MUST* be implemented by any plugin which manage its own items.
* This method is called by the i-MSCP debugger and *MUST* be implemented
* by any plugin which manage its own items.
*
* @return array
*/
@@ -551,25 +552,25 @@ public function getCountRequests()
*
* @param string $migrationMode Migration mode (up|down)
* @return void
* @throws iMSCP_Plugin_Exception When an error occurs
* @throws iMSCP_Plugin_Exception
*/
protected function migrateDb($migrationMode = 'up')
{
try {
$pluginName = $this->getName();
$pluginManager = $this->getPluginManager();
$sqlDir = $pluginManager->pluginGetDirectory() . '/' . $pluginName . '/sql';
$pluginInfo = $pluginManager->pluginGetInfo($pluginName);
$dbSchemaVersion = isset($pluginInfo['db_schema_version']) ? $pluginInfo['db_schema_version'] : '000';
$migrationFiles = [];
$pluginName = $this->getName();
$pm = $this->getPluginManager();
$sqlDir = $pm->pluginGetDirectory() . '/' . $pluginName . '/sql';
$pluginInfo = $pm->pluginGetInfo($pluginName);
$dbSchemaVersion = isset($pluginInfo['db_schema_version']) ? $pluginInfo['db_schema_version'] : '000';
$migrationFiles = [];
try {
if (!@is_dir($sqlDir)) {
// Cover case where there are no longer migration files provided by
// the plugin. In such a case, we need remove the db_schema_version field from
// the plugin info.
if ($migrationMode == 'down') {
unset($pluginInfo['db_schema_version']);
$pluginManager->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
$pm->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
return;
}
@@ -594,11 +595,15 @@ protected function migrateDb($migrationMode = 'up')
foreach ($migrationFiles as $migrationFile) {
if (!@is_readable($migrationFile)) {
throw new iMSCP_Plugin_Exception(tr('Migration file %s is not readable.', $migrationFile));
throw new iMSCP_Plugin_Exception(tohtml(tr(
'Migration file %s is not readable.', $migrationFile
)));
}
if (!preg_match('/(\d+)_[^\/]+\.php$/i', $migrationFile, $version)) {
throw new iMSCP_Plugin_Exception(tr("File %s doesn't look like a migration file.", $migrationFile));
throw new iMSCP_Plugin_Exception(tohtml(tr(
"File %s doesn't look like a migration file.", $migrationFile
)));
}
if (($migrationMode == 'up' && $version[1] > $dbSchemaVersion)
@@ -608,6 +613,7 @@ protected function migrateDb($migrationMode = 'up')
if (isset($migrationFilesContent[$migrationMode])) {
$stmt = $db->prepare($migrationFilesContent[$migrationMode]);
$db->execute($stmt);
/** @noinspection PhpStatementHasEmptyBodyInspection */
while ($stmt->nextRowset()) {
/* https://bugs.php.net/bug.php?id=61613 */
};
@@ -617,12 +623,16 @@ protected function migrateDb($migrationMode = 'up')
}
}
$pluginInfo['db_schema_version'] = ($migrationMode == 'up') ? $dbSchemaVersion : '000';
$pluginManager->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
$pluginInfo['db_schema_version'] = ($migrationMode == 'up')
? $dbSchemaVersion : '000';
$pm->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
} catch (Exception $e) {
$pluginInfo['db_schema_version'] = $dbSchemaVersion;
$pluginManager->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
throw new iMSCP_Plugin_Exception($e->getMessage(), $e->getCode(), $e);
$pm->pluginUpdateInfo($pluginName, $pluginInfo->toArray());
throw new iMSCP_Plugin_Exception(
$e->getMessage(), $e->getCode(), $e
);
}
}
}

0 comments on commit 4de6f87

Please sign in to comment.
You can’t perform that action at this time.