DevGroup-ru /
dotplant2
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace app\components; |
||
| 4 | |||
| 5 | use app; |
||
| 6 | use app\modules\config\models\Configurable; |
||
| 7 | use app\modules\config\helpers\ConfigurationUpdater; |
||
| 8 | use devgroup\TagDependencyHelper\ActiveRecordHelper; |
||
| 9 | use Symfony\Component\Process\Process; |
||
| 10 | use Yii; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Class ExtensionModule is the base module that must use all DotPlant2 extensions |
||
| 14 | * |
||
| 15 | * @package app\components |
||
| 16 | */ |
||
| 17 | abstract class ExtensionModule extends \yii\base\Module |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string Path to migrations folder inside extension root source directory |
||
| 21 | */ |
||
| 22 | public $migrationsFolder = 'migrations'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * ID of module for application config. |
||
| 26 | * You must override it in your extension. |
||
| 27 | */ |
||
| 28 | public static $moduleId = 'temporary-module'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Installs module |
||
| 32 | * @param bool $applyAppMigrations |
||
| 33 | * @param bool $updateComposer |
||
| 34 | * @return mixed |
||
|
0 ignored issues
–
show
|
|||
| 35 | */ |
||
| 36 | public static function installModule($applyAppMigrations = true, $updateComposer = true) |
||
| 37 | { |
||
| 38 | Yii::$app->setModule( |
||
| 39 | static::$moduleId, |
||
| 40 | static::className() |
||
|
0 ignored issues
–
show
static::className() is of type string, but the function expects a object<yii\base\Module>|array|null.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
The method
yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 41 | ); |
||
| 42 | /** @var ExtensionModule $module */ |
||
| 43 | $module = Yii::$app->getModule(static::$moduleId); |
||
| 44 | return $module->updateModule($applyAppMigrations, $updateComposer, true); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Updates/installs module |
||
| 49 | * |
||
| 50 | * @param bool $applyAppMigrations True if we need to apply app migrations |
||
| 51 | * @param bool $updateComposer True if we need to update composer |
||
| 52 | */ |
||
| 53 | public function updateModule($applyAppMigrations = true, $updateComposer = true, $updateConfig = true) |
||
| 54 | { |
||
| 55 | // apply migrations |
||
| 56 | $migrationPath = $this->getMigrationsPath(); |
||
| 57 | |||
| 58 | /** @var Process $process */ |
||
| 59 | $process = Yii::$app->updateHelper |
||
| 60 | ->applyMigrations( |
||
| 61 | $migrationPath, |
||
| 62 | $this->getMigrationTable(), |
||
| 63 | $applyAppMigrations, |
||
| 64 | $updateComposer |
||
| 65 | ); |
||
| 66 | $process->mustRun(); |
||
| 67 | |||
| 68 | |||
| 69 | if ($updateConfig === true) { |
||
| 70 | $this->updateConfig(); |
||
| 71 | } |
||
| 72 | |||
| 73 | return $process->getExitCode() === 0; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Uninstalls module |
||
| 78 | * @return bool True if ok |
||
| 79 | */ |
||
| 80 | public function uninstallModule() |
||
| 81 | { |
||
| 82 | |||
| 83 | $this->removeConfig(); |
||
| 84 | |||
| 85 | // apply migrations |
||
| 86 | $migrationPath = $this->getMigrationsPath(); |
||
| 87 | |||
| 88 | /** @var Process $process */ |
||
| 89 | $process = Yii::$app->updateHelper |
||
| 90 | ->applyMigrations( |
||
| 91 | $migrationPath, |
||
| 92 | $this->getMigrationTable(), |
||
| 93 | false, |
||
| 94 | false, |
||
| 95 | true |
||
| 96 | ); |
||
| 97 | $process->mustRun(); |
||
| 98 | |||
| 99 | return $process->getExitCode() === 0; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return string Full real path to module migrations |
||
| 104 | */ |
||
| 105 | public function getMigrationsPath() |
||
| 106 | { |
||
| 107 | $reflectionClass = new \ReflectionClass($this); |
||
| 108 | $directory = dirname($reflectionClass->getFileName()); |
||
| 109 | |||
| 110 | return realpath( |
||
| 111 | "$directory/{$this->migrationsFolder}/" |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return string Returns name of migration table |
||
| 117 | */ |
||
| 118 | public function getMigrationTable() |
||
| 119 | { |
||
| 120 | return 'migrations_' . md5($this->className()); |
||
|
0 ignored issues
–
show
The method
yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Update configurable config if it exists. |
||
| 125 | * Unexistent values will be filled with default values. |
||
| 126 | */ |
||
| 127 | public function updateConfig() |
||
| 128 | { |
||
| 129 | if ($this->getBehavior('configurableModule') !== null) { |
||
| 130 | // This extension has config behavior |
||
| 131 | |||
| 132 | // Find corresponding configurable |
||
| 133 | $configurable = Configurable::find() |
||
| 134 | ->where(['module' => $this->id]) |
||
| 135 | ->one(); |
||
| 136 | |||
| 137 | if ($configurable !== null) { |
||
| 138 | // We should save default values of it |
||
| 139 | $array = [$configurable]; |
||
| 140 | ConfigurationUpdater::updateConfiguration( |
||
| 141 | $array, |
||
|
0 ignored issues
–
show
$array is of type array<integer,object<yii...\ActiveRecord>|array"}>, but the function expects a array<integer,object<app...g\models\Configurable>>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 142 | false |
||
| 143 | ); |
||
| 144 | |||
| 145 | } |
||
| 146 | |||
| 147 | |||
| 148 | } |
||
| 149 | \yii\caching\TagDependency::invalidate( |
||
| 150 | Yii::$app->cache, |
||
| 151 | [ |
||
| 152 | ActiveRecordHelper::getCommonTag(Configurable::className()), |
||
|
0 ignored issues
–
show
The method
yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 153 | |||
| 154 | ] |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Remove module configuration from config files. |
||
| 160 | */ |
||
| 161 | public function removeConfig() |
||
| 162 | { |
||
| 163 | if ($this->getBehavior('configurableModule') !== null) { |
||
| 164 | // This extension has config behavior |
||
| 165 | |||
| 166 | // Find corresponding configurable |
||
| 167 | $configurables = Configurable::find() |
||
| 168 | ->where('module!=:module', [':module' => $this->id]) |
||
| 169 | ->all(); |
||
| 170 | |||
| 171 | if ($configurables !== null) { |
||
| 172 | // The trick is to use previous saved values from other configurables |
||
| 173 | // and exclude current module from configuration |
||
| 174 | // that is done by setting not to load existing configuration |
||
| 175 | |||
| 176 | ConfigurationUpdater::updateConfiguration( |
||
| 177 | $configurables, |
||
| 178 | false, |
||
| 179 | false |
||
| 180 | ); |
||
| 181 | |||
| 182 | } |
||
| 183 | |||
| 184 | |||
| 185 | } |
||
| 186 | \yii\caching\TagDependency::invalidate( |
||
| 187 | Yii::$app->cache, |
||
| 188 | [ |
||
| 189 | ActiveRecordHelper::getCommonTag(Configurable::className()), |
||
|
0 ignored issues
–
show
The method
yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 190 | |||
| 191 | ] |
||
| 192 | ); |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | } |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.