doneUpdates = $doneUpdates; $this->linkServices = $linkDB; $this->conf = $conf; $this->isLoggedIn = $isLoggedIn; // Retrieve all update methods. $class = new \ReflectionClass($this); $this->methods = $class->getMethods(); } /** * Run all new updates. * Update methods have to start with 'updateMethod' and return true (on success). * * @return array An array containing ran updates. * * @throws UpdaterException If something went wrong. */ public function update() { $updatesRan = array(); // If the user isn't logged in, exit without updating. if ($this->isLoggedIn !== true) { return $updatesRan; } if ($this->methods === null) { throw new UpdaterException('Couldn\'t retrieve LegacyUpdater class methods.'); } foreach ($this->methods as $method) { // Not an update method or already done, pass. if (! startsWith($method->getName(), 'updateMethod') || in_array($method->getName(), $this->doneUpdates) ) { continue; } try { $method->setAccessible(true); $res = $method->invoke($this); // Update method must return true to be considered processed. if ($res === true) { $updatesRan[] = $method->getName(); } } catch (\Exception $e) { throw new UpdaterException($method, $e); } } $this->doneUpdates = array_merge($this->doneUpdates, $updatesRan); return $updatesRan; } /** * @return array Updates methods already processed. */ public function getDoneUpdates() { return $this->doneUpdates; } }