/** * Update object in database */ public function update() { $DB = DB::getInstance(); $AccountID = SessionAccountHandler::getId(); $OldData = isset($_POST['old-data']) ? unserialize(base64_decode($_POST['old-data'])) : array(); if (!is_array($OldData)) { $OldData = array(); } $NewActivity = $this->newActivityObject(); $UpdaterActivity = new \Runalyze\Model\Activity\Updater($DB, $NewActivity, new \Runalyze\Model\Activity\Object($OldData)); if (isset($OldData['routeid']) && $OldData['routeid'] > 0) { $UpdaterActivity->setRoute(\Runalyze\Context::Factory()->route($OldData['routeid'])); } elseif ($this->get('route') != '') { $InserterRoute = new Runalyze\Model\Route\Inserter($DB, new Runalyze\Model\Route\Object(array(Runalyze\Model\Route\Object::NAME => $this->get('route'), Runalyze\Model\Route\Object::CITIES => $this->get('route'), Runalyze\Model\Route\Object::DISTANCE => $this->get('distance')))); $InserterRoute->setAccountID($AccountID); $InserterRoute->insert(); $NewActivity->set(Runalyze\Model\Activity\Object::ROUTEID, $InserterRoute->insertedID()); } $UpdaterActivity->setTrackdata(\Runalyze\Context::Factory()->trackdata($this->id())); $UpdaterActivity->setEquipmentIDs(TrainingFormular::readEquipmentFromPost($NewActivity->sportid()), isset($_POST['equipment_old']) ? explode(',', $_POST['equipment_old']) : array()); $UpdaterActivity->setAccountID($AccountID); $UpdaterActivity->update(); if (isset($OldData['routeid']) && isset($OldData['route'])) { $UpdaterRoute = new \Runalyze\Model\Route\Updater($DB, new Runalyze\Model\Route\Object(array('id' => $OldData['routeid'], Runalyze\Model\Route\Object::NAME => $this->get('route'), Runalyze\Model\Route\Object::CITIES => $this->get('route'))), new Runalyze\Model\Route\Object(array('id' => $OldData['routeid'], Runalyze\Model\Route\Object::NAME => $OldData['route'], Runalyze\Model\Route\Object::CITIES => $OldData['route']))); $UpdaterRoute->setAccountID($AccountID); $UpdaterRoute->update(); } }
/** * Update object in database */ public function update() { $OldData = isset($_POST['old-data']) ? unserialize(base64_decode($_POST['old-data'])) : array(); if (!is_array($OldData)) { $OldData = array(); } $UpdaterActivity = new \Runalyze\Model\Activity\Updater(DB::getInstance(), $this->newActivityObject(), new \Runalyze\Model\Activity\Object($OldData)); if (isset($OldData['routeid'])) { $UpdaterActivity->setRoute(\Runalyze\Context::Factory()->route($OldData['routeid'])); } $UpdaterActivity->setTrackdata(\Runalyze\Context::Factory()->trackdata($this->id())); $UpdaterActivity->setAccountID(SessionAccountHandler::getId()); $UpdaterActivity->update(); if (isset($OldData['routeid']) && isset($OldData['route'])) { $UpdaterRoute = new \Runalyze\Model\Route\Updater(DB::getInstance(), new Runalyze\Model\Route\Object(array('id' => $OldData['routeid'], Runalyze\Model\Route\Object::NAME => $this->get('route'), Runalyze\Model\Route\Object::CITIES => $this->get('route'))), new Runalyze\Model\Route\Object(array('id' => $OldData['routeid'], Runalyze\Model\Route\Object::NAME => $OldData['route'], Runalyze\Model\Route\Object::CITIES => $OldData['route']))); $UpdaterRoute->setAccountID(SessionAccountHandler::getId()); $UpdaterRoute->update(); } }
echo 'Start to calculate '; /** * Run single cleanups */ $Tracks = $PDO->query(' SELECT a.`id`, a.`sportid`, t.`accountid`, t.`time`, t.`distance`, t.`cadence` FROM `' . PREFIX . 'trackdata` as t INNER JOIN `' . PREFIX . 'training` as a ON a.`id` = t.`activityid` WHERE (t.`time` != "" AND t.`distance` != "" AND t.`cadence` != "")'); $Updater = new Runalyze\Model\Activity\Updater($PDO); while ($Track = $Tracks->fetch()) { $Updater->setAccountID($Track['accountid']); GlobalCleanupAccount::$ID = $Track['accountid']; $PDO->setAccountID($Track['accountid']); $Activity = new Runalyze\Model\Activity\Object(array('id' => $Track['id'], Runalyze\Model\Activity\Object::SPORTID => $Track['sportid'])); $Updater->setTrackdata(new Runalyze\Model\Trackdata\Object($Track)); $Updater->update($Activity, array('stride_length')); echo '.' . (CLI ? '' : ' '); } /** * Finish */ echo 'done;' . EOL; echo EOL; echo 'Time: ' . (microtime(true) - $starttime) . 's' . EOL;