예제 #1
0
 public function run()
 {
     switch ($this->mainArgv) {
         case 'generate':
             $gen = new Generators\Generator($this);
             $gen->parseCmd();
             break;
         case 'assets':
             $rules = ['assets' => '', 'action' => ''];
             $opts = new Zend\Console\Getopt($rules);
             $argv = $opts->getArguments();
             if (empty($argv[1])) {
                 $this->terminate("Missing argument 2");
             }
             \Rails::resetConfig('production');
             switch ($argv[1]) {
                 case 'compile:all':
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileAll();
                     break;
                 case strpos($argv[1], 'compile:') === 0:
                     $parts = explode(':', $argv[1]);
                     if (empty($parts[1])) {
                         $this->terminate("Missing asset name to compile");
                     }
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileFile($parts[1]);
                     break;
                 default:
                     $this->terminate("Unknown action for assets");
                     break;
             }
             break;
         case 'routes':
             $routes = $this->createRoutes();
             $rules = ['routes' => '', 'f-s' => ''];
             $opts = new Zend\Console\Getopt($rules);
             if ($filename = $opts->getOption('f')) {
                 if (true === $filename) {
                     $logFile = \Rails::config()->paths->log->concat('routes.log');
                 } else {
                     $logFile = \Rails::root() . '/' . $filename;
                 }
                 file_put_contents($logFile, $routes);
             }
             $this->write($routes);
             break;
             /**
              * Install database.
              */
         /**
          * Install database.
          */
         case 'db:create':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->loadSchema();
             break;
             /**
              * Run all/pending migrations.
              * Creates migrations table as well.
              */
         /**
          * Run all/pending migrations.
          * Creates migrations table as well.
          */
         case 'db:migrate':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->run();
             break;
             /**
              * Runs seeds.
              */
         /**
          * Runs seeds.
          */
         case 'db:seed':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->runSeeds();
             break;
         case 'db:schema:dump':
             $dumper = new \Rails\ActiveRecord\Schema\Dumper(\Rails\ActiveRecord\ActiveRecord::connection());
             $dumper->export(\Rails::root() . '/db/schema.sql');
             break;
     }
 }
예제 #2
0
 public function compileAssets()
 {
     $this->error = '';
     if ($this->request()->isPost()) {
         Rails::resetConfig('production');
         try {
             if ($this->params()->all) {
                 Rails::assets()->compileAll();
             } elseif ($this->params()->file) {
                 $file = $this->params()->file;
                 Rails::assets()->compileFile($file);
             }
         } catch (Rails\Assets\Parser\Javascript\ClosureApi\Exception\ErrorsOnCodeException $e) {
             Rails::log()->error(sprintf("[%s] Asset compilation error for file %s\n%s", date('Y-m-d H:i:s'), $file_path . '.' . $ext, $e->getMessage()));
             $message = sprintf("ClosureAPI reported an error - JS file was saved to %s for verfications, error was logged.<br /><pre>%s</pre>", Rails\Assets\Parser\Javascript\ClosureApi\ClosureApi::errorFile(), $e->getMessage());
             $this->error = $message;
         } catch (Throwable $e) {
             /** 
              * If another error occurs, it won't be properly shown because of production config.
              */
             Rails::resetConfig('development');
             throw $e;
         } catch (\Exception $e) {
             /** 
              * If another error occurs, it won't be properly shown because of production config.
              */
             Rails::resetConfig('development');
             throw $e;
         }
         Rails::resetConfig('development');
         Rails::application()->setPanelConfig();
     }
 }