protected function execute($arguments = array(), $options = array()) { if ( !$options['appmin'] || !$options['appmax'] || ($options['appmin'] > $options['appmax'])) { throw new Exception("invalid option: "); } $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $applist = range($options['appmin'], $options['appmax']); foreach ($applist as $application_id) { $sql = 'SELECT id FROM application WHERE id = ?'; $where = array(intval($application_id)); $app = $this->conn->fetchOne($sql, $where); if (!$app) { $application = new Application(); $application->setUrl("http://"); $application->setIsMobile('1'); $application->setIsPc('0'); $application->save(); $application->free(); $this->logSection('application', sprintf("%s", $application_id)); } } }
/** * add a new application * * @param string $url * @param boolean $update * @param string $culture * @return Application */ public function addApplication($url, $update = false, $culture = null) { if ($culture === null) { $culture = sfContext::getInstance()->getUser()->getCulture(); } if ($culture != sfConfig::get('sf_default_culture')) { self::addApplication($url, $update, sfConfig::get('sf_default_culture')); } $application = $this->findOneByUrl($url); if (!$application) { $application = new Application(); } if (isset($application->Translation[$culture]) && !$update) { $ua = $application->getUpdatedAt(); $time = strtotime($ua); if (!empty($ua) && time() - $ua <= Doctrine::getTable('SnsConfig')->get('application_cache_time', 24 * 60 * 60)) { return $application; } } $gadget = opOpenSocialToolKit::fetchGadgetMetadata($url, $culture); $prefs = array(); foreach ($gadget->gadgetSpec->userPrefs as $pref) { $prefs[$pref['name']] = $pref; } $views = array(); foreach ($gadget->gadgetSpec->views as $name => $view) { unset($view['content']); $views[$name] = $view; } $translation = $application->Translation[$culture]; $application->setUrl($url); $application->setLinks($gadget->gadgetSpec->links); $translation->title = $gadget->getTitle(); $translation->title_url = $gadget->getTitleUrl(); $translation->description = $gadget->getDescription(); $translation->directory_title = $gadget->getDirectoryTitle(); $translation->screenshot = $gadget->getScreenShot(); $translation->thumbnail = $gadget->getThumbnail(); $translation->author = $gadget->getAuthor(); $translation->author_aboutme = $gadget->getAuthorAboutme(); $translation->author_affiliation = $gadget->getAuthorAffiliation(); $translation->author_email = $gadget->getAuthorEmail(); $translation->author_photo = $gadget->getAuthorPhoto(); $translation->author_link = $gadget->getAuthorLink(); $translation->author_quote = $gadget->getAuthorQuote(); $translation->settings = $prefs; $translation->views = $views; if (isset($views['mobile'])) { if (!(isset($views['mobile']['type']) && 'URL' === strtoupper($views['mobile']['type']))) { throw new Exception(); } } $application->setIsPc(true); if (count($views) == 1) { if (isset($views['mobile'])) { $application->setIsPc(false); } } if ($application->getIsMobile()) { if (!isset($views['mobile'])) { $application->setIsMobile(false); } } if ($gadget->getScrolling() == 'true') { $application->setScrolling(true); } else { $application->setScrolling(false); } $singleton = $gadget->getSingleton(); if ($singleton == 'true' || empty($singleton)) { $application->setSingleton(true); } else { $application->setSingleton(false); } $height = $gadget->getHeight(); $application->setHeight(!empty($height) ? $height : 0); $application->save(); return $application; }