/** * Refreshes the model with the extension * data from the channel * * @return void */ public function refreshAction() { // set the maximum execution time to endless ini_set('max_execution_time', 0); // load the helper and the registry $helper = Mage::helper('manager'); // initialize the channel model $chn = Mage::getModel('manager/channel'); $collection = $chn->getCollection(); // load the ID of the select channel from the session $channelId = Mage::getSingleton('adminhtml/session')->getData(Faett_Manager_Helper_Data::CHANNEL_ID); // log a message Mage::log('Found channel with ID ' . $channelId . ' in session'); // if a channelId was found in the session add a filter for it if (!empty($channelId)) { $collection->addFieldToFilter('channel_id', $channelId); } // iterate over the channel and load initialize the packages foreach ($collection as $c) { try { // get the URL of the channel to refresh $packages = $this->_service->listPackages($channelName = $c->getUrl()); } catch (Exception $e) { // attach a message to the session Mage::getSingleton('adminhtml/session')->addError($helper->__($e->getKey(), $e->getMessage())); // continue with the next channel continue; } // load the the packages foreach ($packages as $packageName) { try { // load the package information $package = $this->_service->packageInfo($packageName, $channelName); } catch (Faett_Core_Exceptions_UnknownChannelStateException $e) { // attach a message to the session Mage::getSingleton('adminhtml/session')->addError($helper->__($e->getKey(), $e->getMessage())); // continue with the next channel continue; } catch (Faett_Core_Exceptions_PackageInfoException $e) { // attach a message to the session Mage::getSingleton('adminhtml/session')->addError($helper->__($e->getKey(), $e->getMessage())); // continue with the next channel continue; } catch (Exception $e) { // attach a message to the session Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); // continue with the next channel continue; } // initialize the package model $pkg = Mage::getModel('manager/package'); // try to load the package from the database by its name $id = $pkg->loadByName($packageName)->getId(); if (empty($id)) { // if the package is new, create it $pkg->setChannelIdFk($c->getId()); $pkg->setName($packageName); $pkg->setSummary($package['summary']); $pkg->setVersionInstalled($package['installed']); if (is_array($package['releases'])) { $pkg->setVersionLatest(reset(array_keys($package['releases']))); } $pkg->setCreatedTime(now()); $pkg->setUpdateTime(now()); } else { // if the package already exists update it $pkg->setSummary($package['summary']); $pkg->setVersionInstalled($package['installed']); if (is_array($package['releases'])) { $pkg->setVersionLatest(reset(array_keys($package['releases']))); } $pkg->setUpdateTime(now()); } // set the package state $pkg->setState($helper->getPackageState($pkg)); // save the package $pkg->save(); // check if the package has releases if (is_array($package['releases'])) { // load and initialize the releases foreach ($package['releases'] as $version => $release) { // initialize the release model $rel = Mage::getModel('manager/release'); // try to load the release from the databas by // its package and version $relId = $rel->loadByPackageAndVersion($pkg, $version)->getId(); // check if a release was found if (empty($relId)) { // if the package is new, create it $rel->setPackageIdFk($pkg->getId()); $rel->setVersion($version); $rel->setCreatedTime(now()); $rel->setUpdateTime(now()); } // save the release $rel->save(); } } else { // attach a message to the session Mage::getSingleton('adminhtml/session')->addError($helper->__('201.error.package-no-releases', $packageName)); } // attach a message to the session Mage::getSingleton('adminhtml/session')->addSuccess($helper->__('201.success.package-update', $packageName)); } // attach a message to the session Mage::getSingleton('adminhtml/session')->addSuccess($helper->__('201.success.channel-update', $channel)); } // log a message with the message logged by PEAR Mage::log($this->_service->getUI()->getLogText()); // redirect to the licence overview $this->_redirect('*/*/'); }