/** * Record package details in the database * * @param string $package Name of the Composer Package * @param string $installed Currently installed version * @param string|boolean $latest The latest available version */ private function recordUpdate($package, $installed, $latest) { // Is there a record already for the package? If so find it. $packages = ComposerUpdate::get()->filter(array('Name' => $package)); // if there is already one use it otherwise create a new data object if ($packages->count() > 0) { $update = $packages->first(); } else { $update = new ComposerUpdate(); $update->Name = $package; } // If installed is dev-master get the hash if ($installed === 'dev-master') { $localPackage = $this->getLocalPackage($package); $installed = $localPackage->source->reference; } // Set the new details and save it $update->Installed = $installed; $update->Available = $latest; $update->write(); }
/** * Record package details in the database * * @param string $package Name of the Composer Package * @param string $installed Currently installed version * @param string $latest The latest available version * @return bool TRUE if the package can be updated */ private function recordUpdate($package, $installed, $latest) { // Is there a record already for the package? $model = ComposerUpdate::get()->find('Name', $package); if (!$model) { $model = new ComposerUpdate(); $model->Name = $package; } // What was the last known update $lastKnown = $model->Available; // If installed is dev-master, get the hash if ($installed === 'dev-master') { $localPackage = $this->getLocalPackage($package); $installed = $localPackage->source->reference; } // If latest is false, make it the same as installed if ($latest === false) { $latest = $installed; } // Set the new details $model->Installed = $installed; $model->Available = $latest; // Save it $model->write(); // Is the latest different to the last known? if ($latest != $lastKnown) { // Is it different to what's installed? if ($latest != $installed) { // It's an update! return true; } } // It's not an update return false; }