/** * Finds new (not applied) migrations * * @return array */ public function findNewMigrations() { $appliedMigrations = $this->getAppliedMigrations(); $migrationPaths = PathHelper::getTargetPaths($this->migrationPaths, $this->module, $this->modulesDir, $this->migrationDir); $migrations = []; if (count($migrationPaths) > 0) { foreach ($migrationPaths as $migrationPath) { $migrationRealPath = Yii::getAlias($migrationPath); if (is_dir($migrationRealPath)) { $handle = opendir($migrationRealPath); while (($file = readdir($handle)) !== false) { if ($file === '.' || $file === '..') { continue; } $path = $migrationRealPath . DIRECTORY_SEPARATOR . $file; if (preg_match('/^(m(\\d{6}_\\d{6})_.*?)\\.php$/', $file, $matches) && is_file($path)) { $migration = $this->formatMigration($file, $migrationPath); if (!isset($appliedMigrations[$migration['name'] . '/' . $migration['module']])) { $migrations[$migration['name'] . '/' . $migration['module']] = $migration; } } } closedir($handle); } } } ksort($migrations); return $migrations; }
/** * Gather all i18n messages files * * @return array */ public function loadI18n() { $i18nPaths = PathHelper::getTargetPaths($this->configPaths, $this->module, $this->modulesDir, $this->i18nDir, false); $i18nConfig = ['components' => ['i18n' => ['translations' => []]]]; foreach ($i18nPaths as $i18nPath) { $realPath = Yii::getAlias($i18nPath); if (is_dir($realPath)) { $fileMap = []; $handle = opendir($realPath); $categoryPrefix = 'c'; $categoryName = ''; while (($dir = readdir($handle)) !== false) { if ($dir === '.' || $dir === '..') { continue; } if (is_dir($realPath . DIRECTORY_SEPARATOR . $dir)) { if (!$categoryName) { foreach ($this->configPaths as $configPath) { if (strpos($realPath, substr($configPath, 1)) !== false) { $categoryPrefix = substr($configPath, 1, 1); break; } } $categoryName = PathHelper::getModuleAlias($realPath . DIRECTORY_SEPARATOR . $dir, $this->i18nDir, $this->modulesDir); $categoryName = $categoryPrefix . '/' . $categoryName; } $filesHandle = opendir($realPath . DIRECTORY_SEPARATOR . $dir); while (($file = readdir($filesHandle)) !== false) { if ($file === '.' || $file === '..') { continue; } $categoryAlias = str_replace('.php', '', $file); if ($categoryPrefix . '/' . $categoryAlias == $categoryName) { $fileMap[$categoryName] = $file; } else { $fileMap[$categoryName . '/' . $categoryAlias] = $file; } } closedir($filesHandle); } } closedir($handle); $i18nConfig['components']['i18n']['translations'][$categoryName . '*'] = ['class' => $this->i18nClass, 'basePath' => $i18nPath, 'forceTranslation' => true, 'fileMap' => $fileMap]; } } $this->config = ArrayHelper::merge($this->config, $i18nConfig); }