argument('name')); $method = 'util'.studly_case($command); if (!method_exists($this, $method)) { $this->error(sprintf('Utility command "%s" does not exist!', $command)); return; } $this->$method(); } /** * Get the console command arguments. * @return array */ protected function getArguments() { return [ ['name', InputArgument::IS_ARRAY, 'A utility command to perform.'], ]; } /** * Get the console command options. */ protected function getOptions() { return [ ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], ]; } // // Utilties // protected function utilCompileJs() { $this->utilCompileAssets('js'); } protected function utilCompileLess() { $this->utilCompileAssets('less'); } protected function utilCompileAssets($type = null) { $this->comment('Compiling registered asset bundles...'); Config::set('cms.enableAssetMinify', true); $combiner = CombineAssets::instance(); $bundles = $combiner->getBundles($type); if (!$bundles){ $this->comment('Nothing to compile!'); return; } if ($type) { $bundles = [$bundles]; } foreach ($bundles as $bundleType) { foreach ($bundleType as $destination => $assets) { $destination = File::symbolizePath($destination); $publicDest = File::localToPublic(realpath(dirname($destination))) . '/' . basename($destination); $combiner->combineToFile($assets, $destination); $shortAssets = implode(', ', array_map('basename', $assets)); $this->comment($shortAssets); $this->comment(sprintf(' -> %s', $publicDest)); } } } protected function utilPurgeThumbs() { if (!$this->confirmToProceed('This will PERMANENTLY DELETE all thumbs in the uploads directory.')) { return; } $totalCount = 0; $uploadsPath = Config::get('filesystems.disks.local.root', storage_path().'/app'); $uploadsPath .= '/uploads'; /* * Recursive function to scan the directory for files beginning * with "thumb_" and repeat itself on directories. */ $purgeFunc = function ($targetDir) use (&$purgeFunc, &$totalCount) { if ($files = File::glob($targetDir.'/thumb_*')) { foreach ($files as $file) { $this->info('Purged: '. basename($file)); $totalCount++; @unlink($file); } } if ($dirs = File::directories($targetDir)) { foreach ($dirs as $dir) { $purgeFunc($dir); } } }; $purgeFunc($uploadsPath); if ($totalCount > 0) { $this->comment(sprintf('Successfully deleted %s thumbs', $totalCount)); } else { $this->comment('No thumbs found to delete'); } } protected function utilPurgeUploads() { if (!$this->confirmToProceed('This will PERMANENTLY DELETE files in the uploads directory that do not exist in the "system_files" table.')) { return; } // @todo } protected function utilPurgeOrphans() { if (!$this->confirmToProceed('This will PERMANENTLY DELETE files in "system_files" that do not belong to any other model.')) { return; } // @todo } }