public function play() { $this->assertLoggedIn(); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } else { throw new Exception("Could not find that bot."); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } if ($bot->get('status') != 'paused') { throw new Exception("Bot must be paused to unpause a job."); } $job = $bot->getCurrentJob(); if (!$job->isHydrated()) { throw new Exception("Job must be a real job."); } if (!$bot->canDrop($job)) { throw new Exception("Job cannot be dropped."); } //okay, unpause it. $bot->unpause(); Activity::log("unpaused the bot " . $bot->getLink() . "."); $this->forwardToUrl("/"); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Unpause Job - Error"); } }
public function api_updatebot() { if (!$this->args('bot_id')) { throw new Exception("You must provide the 'bot_id' parameter."); } $bot = new Bot($this->args('bot_id')); if (!$bot->isHydrated()) { throw new Exception("Bot does not exist."); } if (!$bot->isMine()) { throw new Exception("This bot is not yours."); } //if (!$this->args('manufacturer')) // throw new Exception('Bot manufacturer is a required parameter.'); //if (!$this->args('model')) // throw new Exception('Bot model is a required parameter.'); if ($this->args('name')) { $bot->set('name', $this->args('name')); } if ($this->args('name')) { $bot->set('identifier', $this->args('identifier')); } if ($this->args('manufacturer')) { $bot->set('manufacturer', $this->args('manufacturer')); } if ($this->args('model')) { $bot->set('model', $this->args('model')); } if ($this->args('electronics')) { $bot->set('electronics', $this->args('electronics')); } if ($this->args('firmware')) { $bot->set('firmware', $this->args('firmware')); } if ($this->args('extruder')) { $bot->set('extruder', $this->args('extruder')); } if ($this->args('status')) { $bot->set('status', $this->args('status')); } if ($this->args('error_text')) { $bot->set('error_text', $this->args('error_text')); } $bot->save(); Activity::log("updated the bot " . $bot->getLink() . " via the API."); return $bot->getAPIData(); }
public function set_status() { $this->assertLoggedIn(); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } if ($bot->get('status') == 'working' && $this->args('status') == 'offline') { throw new Exception("You cannot take a working bot offline through the web interface. Use the client app instead."); } if ($this->args('status') == 'offline') { Activity::log("took the bot " . $bot->getLink() . " offline."); } else { Activity::log("brought the bot " . $bot->getLink() . " online."); } $bot->set('status', $this->args('status')); $bot->save(); $this->forwardToUrl($bot->getUrl()); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Change Bot Status - Error"); } }