/** * Imports the WURFL resource file from the specified source * (local or remote). * * @param boolean $force Force update (only valid for type "remote") * * @return integer Import status code, see class constants */ public function import($force = false) { if ($this->type === TeraWurflUpdater::SOURCE_REMOTE) { // Use download url from extension configuration $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['contexts_wurfl']); if (empty($extConf['remoteRepository'])) { return self::STATUS_NOT_CONFIGURED; } $this->updater->downloader->download_url = $extConf['remoteRepository']; try { $available = $this->updater->isUpdateAvailable(); } catch (Exception $ex) { $available = true; } // No update available, WURFL data is already up to date if (!$force && !$available) { return self::STATUS_NO_UPDATE; } } try { // update() returns TRUE or FALSE return $this->updater->update(); } catch (TeraWurflUpdateDownloaderException $ex) { return self::STATUS_ERROR; } return true; }
protected function actionUpdate(TeraWurflCLIArgument $arg) { $update_source = $arg->value; if ($update_source != 'local' && $update_source != 'remote') { throw new TeraWurflCLIInvalidArgumentException("You must specify a valid source when using the --update option. Use --help for help\n\n"); } $updater = new TeraWurflUpdater($this->wurfl, $update_source); $updater->setVerbose(); $force_update = $this->arguments->exists('force'); if ($update_source == 'remote') { try { $available = $updater->isUpdateAvailable(); } catch (Exception $e) { echo "Unable to check if update is available, assuming it is.\n"; $available = true; } if (!$force_update && !$available) { echo "Use --force to force an update.\n"; return; } } try { $status = $updater->update(); } catch (TeraWurflUpdateDownloaderException $e) { echo "\n" . $e->getMessage() . "\n"; if ($updater->downloader->download_url == 'http://downloads.sourceforge.net/project/wurfl/WURFL/latest/wurfl-latest.zip') { echo <<<EOL The license of the WURFL Data has recently changed. ScientiaMobile has temporarily moved the WURFL download location to ensure that you are aware of the changes. Please download the wurfl.xml file manually and place it in the data/ directory, then run --update=local EOL; } return; } if ($status) { echo "Database Update OK\n"; echo "Total Time: " . $updater->loader->totalLoadTime() . "\n"; echo "Parse Time: " . $updater->loader->parseTime() . " (" . $updater->loader->getParserName() . ")\n"; echo "Validate Time: " . $updater->loader->validateTime() . "\n"; echo "Sort Time: " . $updater->loader->sortTime() . "\n"; echo "Patch Time: " . $updater->loader->patchTime() . "\n"; echo "Database Time: " . $updater->loader->databaseTime() . "\n"; echo "Cache Rebuild Time: " . $updater->loader->cacheRebuildTime() . "\n"; echo "Number of Queries: " . $this->wurfl->db->numQueries . "\n"; if (version_compare(PHP_VERSION, '5.2.0') === 1) { echo "PHP Memory Usage: " . WurflSupport::formatBytes(memory_get_usage()) . "\n"; } echo "--------------------------------\n"; echo "WURFL Version: " . $updater->loader->version . " (" . $updater->loader->last_updated . ")\n"; echo "WURFL Devices: " . $updater->loader->mainDevices . "\n"; echo "PATCH New Devices: " . $updater->loader->patchAddedDevices . "\n"; echo "PATCH Merged Devices: " . $updater->loader->patchMergedDevices . "\n"; if (count($updater->loader->errors) > 0) { echo "\nThe following errors were encountered:\n"; foreach ($updater->loader->errors as $error) { echo " * {$error}\n"; } } } else { echo "ERROR LOADING DATA!\n"; echo "Errors: \n\n"; foreach ($updater->loader->errors as $error) { echo "{$error}\n"; } } }
$wurfl = new TeraWurfl(); $updater = new TeraWurflUpdater($wurfl, $update_source); if (isset($_GET['action']) && $_GET['action'] == 'rebuildCache') { $wurfl->db->rebuildCacheTable(); header("Location: index.php?msg=" . urlencode("The cache has been successfully rebuilt ({$wurfl->db->numQueries} queries).") . "&severity=notice"); exit(0); } if (isset($_GET['action']) && $_GET['action'] == 'clearCache') { $wurfl->db->createCacheTable(); header("Location: index.php?msg=" . urlencode("The cache has been successfully cleared ({$wurfl->db->numQueries} queries).") . "&severity=notice"); exit(0); } $force_update = isset($_GET['force']); if ($update_source == 'remote') { try { $available = $updater->isUpdateAvailable(); } catch (Exception $e) { //echo "Unable to check if update is available, assuming it is.\n"; $available = true; } if (!$force_update && !$available) { header("Location: index.php?msg=" . urlencode("Your WURFL data is already up to date. <a href=\"updatedb.php?source=remote&force=true\">Force update</a>") . "&severity=notice"); exit(0); } } try { $status = $updater->update(); } catch (TeraWurflUpdateDownloaderException $e) { $sf = $updater->downloader->download_url == 'http://downloads.sourceforge.net/project/wurfl/WURFL/latest/wurfl-latest.zip'; header("Location: index.php?msg=" . urlencode($e->getMessage()) . "&severity=error&sf404=" . $sf); exit(0);