Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 17, 2021
2 parents 39e9b55 + 84fad85 commit 1c77e28
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
18 changes: 12 additions & 6 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -4913,14 +4913,20 @@ function ($v) {
$dir = new DirectoryIterator(APPPATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'plugins');
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$plugin = Plugin::model()->findByAttributes(
['name' => $fileinfo->getFilename()]
);
$plugin = $oDB->createCommand()
->select('*')
->from('{{plugins}}')
->where("name = :name", [':name' => $fileinfo->getFilename()])
->queryRow();

if (!empty($plugin)) {
if ($plugin->plugin_type !== 'core') {
$plugin->plugin_type = 'core';
$plugin->save();
if ($plugin['plugin_type'] !== 'core') {
$oDB->createCommand()->update(
'{{plugins}}',
['plugin_type' => 'core'],
'name = :name',
[':name' => $plugin->name]
);
}
} else {
// Plugin in folder but not in database?
Expand Down
6 changes: 4 additions & 2 deletions application/libraries/PluginManager/PluginManager.php
Expand Up @@ -59,8 +59,10 @@ class PluginManager extends \CApplicationComponent
public $shutdownObject;

/**
* Creates the plugin manager.
* Loads all active plugins.
* Creates the plugin manager. Loads all active plugins.
* If $plugin->save() is used in this method, it can lead to an infinite event loop,
* since beforeSave tries to get the PluginManager, which executes init() again.
*
* @return void
*/
public function init()
Expand Down
21 changes: 12 additions & 9 deletions application/models/Plugin.php
Expand Up @@ -67,7 +67,7 @@ public function tableName()
/**
* Set this plugin as load error in database, and saves the error message.
* @param array $error Array with 'message' and 'file' keys (as get from error_get_last).
* @return boolean Update result.
* @return int Rows affected
*/
public function setLoadError(array $error)
{
Expand Down Expand Up @@ -295,20 +295,23 @@ protected function getUninstallButton()
* @param Plugin|null $plugin
* @param string $pluginName
* @param array $error Array with 'message' and 'file' keys (as get from error_get_last).
* @return boolean
* @return int Rows affected
*/
public static function setPluginLoadError($plugin, $pluginName, array $error)
{
if ($plugin) {
$result = $plugin->setLoadError($error);
} else {
// TODO: Use raw SQL insteadl of active records.
$plugin = new \Plugin();
$plugin->name = $pluginName;
$plugin->active = 0;
$result1 = $plugin->save();
$result2 = $plugin->setLoadError($error);
$result = $result1 && $result2;
$result = Yii::app()->db->createCommand()
->insert(
'{{plugins}}',
[
'name' => $pluginName,
'active' => 0,
'load_error' => 1,
'load_error_message' => addslashes($error['message'] . ' ' . $error['file'])
]
);
}
return $result;
}
Expand Down

0 comments on commit 1c77e28

Please sign in to comment.