/** * @param $from * @param $to * @param $isValid */ public function checkState($from, $to, $isValid) { $bot = new Bot(); $bot->setStatus(BotState::Offline); // Setup by transition to the correct state foreach ($this->setup[$from] as $val) { $bot->setStatus($val); } $this->assertEquals($bot->getStatus(), $from); $exceptionThrown = false; try { $bot->setStatus($to); } catch (InvalidStateChange $ex) { $exceptionThrown = true; } if ($isValid) { $this->assertEquals($bot->getStatus(), $to); } else { $this->assertEquals($bot->getStatus(), $from); if (!$exceptionThrown) { $this->fail($from . " to " . $to . " Failed"); } } }
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('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')) { //todo Change this to get the status in BotStatus so we know it's valid $bot->setStatus($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')); } else { throw new Exception("This shouldn't happen"); } //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') == 'retired') { throw new Exception("This bot is retired. You can't change it's status"); } if (($bot->get('status') == 'working' || $bot->get('status') == 'slicing') && $this->args('status') == 'offline') { throw new Exception("You cannot take a working bot offline through the web interface. You must stop the job from the client first."); } if ($this->args('status') == 'offline') { Activity::log("took the bot " . $bot->getLink() . " offline."); } else { Activity::log("brought the bot " . $bot->getLink() . " online."); } //do we need to drop a job? $job = $bot->getCurrentJob(); if ($job->isHydrated()) { $bot->dropJob($job); } //save it and clear out some junk $bot->set('temperature_data', ''); $bot->set('error_text', ''); $bot->setStatus($this->args('status')); $bot->save(); $this->forwardToUrl("/"); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Change Bot Status - Error"); } }