$patchNumber = 12; start_patch(); if (!patch_exists($patchNumber)) { // Fix the temperature fields: $rs = db()->query("SELECT * from jobs"); while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { $job = new Job($row['id']); $fixed_data = fix_temp_data($job->get('temperature_data')); $job->set('temperature_data', $fixed_data); $job->save(); } $rs = db()->query("SELECT * from bots"); while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { $bot = new Bot($row['id']); $fixed_data = fix_temp_data($bot->get('temperature_data')); $bot->set('temperature_data', $fixed_data); $bot->save(); } $expandTemperatureData = "\n\t\tALTER TABLE jobs\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL"; db()->execute($expandTemperatureData); $expandTemperatureData = "\n\t\tALTER TABLE bots\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL"; finish_patch($patchNumber, "Expanded temperature data fields"); } function fix_temp_data($data) { if (strlen($data) == 0) { return ""; } $data .= "}"; while (JSON::decode($data) === null) { // Remove last two characters
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"); } }
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"); } }