/** * Fire the command * * @return void * @author Dan Cox */ public function fire() { if (Command::exists($this->input->getArgument('name'), 'name')) { $command = Command::db()->first(['name' => $this->input->getArgument('name')]); $config = $this->DI->get('config'); $config->load(CONFIG . $command->file); $cmds = $config->params()->commands; $this->params = $config->params()->parameters; // If there is a directory stated in the params, we use that, else we use input if (!isset($this->params['directory'])) { $this->params['directory'] = $this->input->getArgument('directory'); } // We want to be able to test these, so load them as processes foreach ($cmds as $comm) { $p = $this->hasProcessDefinition($comm); try { $p->mustRun(); $cmd = $p->getCommandLine(); $this->output->writeln("Ran command: {$cmd}"); } catch (\Exception $e) { $this->output->writeln("Unable to run command..."); $this->output->writeln($e->getMessage()); } } $this->output->writeln("Finished running command line chain..."); return true; } throw new \RuntimeException("The command does not exist"); }
/** * Fire command * * @return void * @author Dan Cox */ public function fire() { $job = NULL; $command = NULL; $cmd = $this->input->getOption('cmd'); $commandList = $this->input->getOption('commandlist'); if (!empty($cmd)) { $this->createCronFromCMD(); $this->cronprocess->build()->getProcess()->mustRun(); $this->output->writeln('Created cron job with the provided commands'); return true; } if (!empty($commandList)) { $command = $this->input->getOption('commandlist'); if (Command::exists($command, 'name')) { $this->createCronFromCommandList(); $this->cronprocess->build()->getProcess()->mustRun(); $this->output->writeln("Created cron job from command list {$command}"); return true; } else { throw new \RuntimeException('The commandlist you provide does not exist, either create it first or use a different one.'); } } throw new \RuntimeException("You must provide either the command name or a set of commands"); }
/** * Fire the command * * @return void * @author Dan Cox */ public function fire() { $name = $this->input->getArgument('name'); $cmd = $this->input->getOption('cmd'); $commandList = $this->input->getOption('commandlist'); $time = $this->input->getOption('time'); if (Cron::exists($name, 'name')) { $cron = Cron::db()->first(['name' => $name]); if (!empty($cmd)) { $cron->job = $cmd; $cron->command = NULL; } elseif (!empty($commandList)) { if (Command::exists($commandList, 'name')) { $cron->job = NULL; $cron->command = $commandList; } else { throw new \RuntimeException("Command list does not exist"); } } // Update the time if its set if (!empty($time)) { $cron->jobdate = $time; } $cron->save(); $this->output->writeln('Saved updates to cron'); return; } throw new \RuntimeException("The cron you specified does not exist"); }
/** * Attempts to run a command list * * @return void * @author Dan Cox */ public function runCronFromCommandList() { if (Command::exists($this->cron->command, 'name')) { $this->makeSkeletonProcess('php alice command:run ' . $this->cron->command . ' ' . ROOT); return true; } $this->logCronResults('Failed to find command list by name: ' . $this->cron->command); throw new \RuntimeException("The command list for this cron job does not exist"); }