| 1: | <?php |
| 2: | |
| 3: | namespace Aurora\System\Console\Commands; |
| 4: | |
| 5: | use Symfony\Component\Console\Command\Command; |
| 6: | use Illuminate\Support\Facades\File; |
| 7: | use Symfony\Component\Finder\Finder; |
| 8: | use Symfony\Component\Finder\SplFileInfo; |
| 9: | |
| 10: | class BaseCommand extends Command |
| 11: | { |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | protected function getMigrationPaths($input) |
| 18: | { |
| 19: | |
| 20: | |
| 21: | |
| 22: | if ($input->getOption('path')) { |
| 23: | return collect($input->getOption('path'))->map(function ($path) use ($input) { |
| 24: | return !$this->usingRealPath($input) |
| 25: | ? \Aurora\Api::RootPath() . $path |
| 26: | : $path; |
| 27: | })->all(); |
| 28: | } |
| 29: | |
| 30: | return array_merge( |
| 31: | [$this->getSystemMigrationsPath()], |
| 32: | $this->migrator->paths(), |
| 33: | $this->getMigrationPath() |
| 34: | ); |
| 35: | } |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | protected function usingRealPath($input) |
| 43: | { |
| 44: | return $input->hasOption('realpath') && $input->getOption('realpath'); |
| 45: | } |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | protected function getMigrationPath($sRequiredModule = null) |
| 54: | { |
| 55: | if ($sRequiredModule) { |
| 56: | if ($sRequiredModule === 'system') { |
| 57: | $sPath = $this->getSystemMigrationsPath(); |
| 58: | } else { |
| 59: | $sPath = \Aurora\Api::GetModuleManager()->GetModulePath($sRequiredModule) . $sRequiredModule . DIRECTORY_SEPARATOR . 'Migrations'; |
| 60: | } |
| 61: | |
| 62: | if (!file_exists($sPath)) { |
| 63: | mkdir($sPath, 0755, true); |
| 64: | } |
| 65: | |
| 66: | return $sPath; |
| 67: | } else { |
| 68: | $aModules = \Aurora\Api::GetModuleManager()->GetModulesPaths(); |
| 69: | return array_map(function ($sModule, $sPath) { |
| 70: | return $sPath . $sModule . DIRECTORY_SEPARATOR . 'Migrations'; |
| 71: | }, array_keys($aModules), $aModules); |
| 72: | } |
| 73: | } |
| 74: | |
| 75: | public function getAllModels() |
| 76: | { |
| 77: | $modules = \Aurora\Api::GetModuleManager()->GetModulesPaths(); |
| 78: | |
| 79: | array_walk($modules, function (&$modelPath, $module) { |
| 80: | $modelPath = $modelPath . $module . DIRECTORY_SEPARATOR . 'Models'; |
| 81: | }); |
| 82: | |
| 83: | $dirModels = []; |
| 84: | foreach ($modules as $module => $moduleModelPath) { |
| 85: | $finder = Finder::create(); |
| 86: | if (is_dir($moduleModelPath)) { |
| 87: | $finder |
| 88: | ->in($moduleModelPath) |
| 89: | ->depth(0); |
| 90: | $dirModels[$module] = array_keys(\iterator_to_array($finder)); |
| 91: | } |
| 92: | } |
| 93: | |
| 94: | $formatedDirModels = []; |
| 95: | foreach ($dirModels as $module => $moduleDirModels) { |
| 96: | foreach ($moduleDirModels as $dirModel) { |
| 97: | $modelName = pathinfo($dirModel, PATHINFO_FILENAME); |
| 98: | $formatedDirModels[$module][$modelName] = dirname($dirModel) . DIRECTORY_SEPARATOR . $modelName; |
| 99: | } |
| 100: | } |
| 101: | return $formatedDirModels; |
| 102: | } |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | private function getSystemMigrationsPath() |
| 108: | { |
| 109: | return \Aurora\Api::RootPath() . DIRECTORY_SEPARATOR . 'Migrations'; |
| 110: | } |
| 111: | } |
| 112: | |