Exemple #1
0
	/** @var UpdateSiteModel $site */
	if(!$site->isValid()){
		CLI::PrintActionStatus('failed');
		continue;
	}

	++$sitecount;
	$file = $site->getFile();

	$repoxml = new RepoXML();
	$repoxml->loadFromFile($file);
	$rootpath = dirname($file->getFilename()) . '/';

	CLI::PrintActionStatus('ok');

	foreach($repoxml->getPackages() as $pkg){
		/** @var PackageXML $pkg */

		$n = str_replace(' ', '-', strtolower($pkg->getName()));
		$type = $pkg->getType();
		$location = $pkg->getFileLocation();
		if(strpos($location, '://') === false){
			// The remote location may or may not be fully resolved.
			$location = $rootpath . $location;
		}

		switch($type){
			case 'component':
				$vers = $pkg->getVersion();

				// Only display the newest version available.
	/**
	 * Perform a lookup on any repository sites installed and get a list of provided pacakges.
	 *
	 * @return array
	 */
	public static function GetUpdates(){
		// Allow this to be cached for x amount of time.  This will save the number of remote requests.
		//if(false && isset($_SESSION['updaterhelper_getupdates']) && $_SESSION['updaterhelper_getupdates']['expire'] <= time()){
		//	return $_SESSION['updaterhelper_getupdates']['data'];
		//}

		// Build a list of components currently installed, this will act as a base.
		$components = array();
		$core       = array();
		$themes     = array();
		$sitecount  = 0;
		$pkgcount   = 0;
		$current    = Core::GetComponents();
		$froze      = \ConfigHandler::Get('/core/updater/versionfreeze');

		// If Core isn't installed yet, GetComponents will yield null.
		if($current === null) $current = array();

		/** @var string $backportVersion Add support for "~bpoXYZ" version strings for backported packages. */
		$coreVersion      = Core::GetVersion();
		$coreVersionParts = Core::VersionSplit($coreVersion);
		$backportVersion  = '~bpo' . $coreVersionParts['major'] . $coreVersionParts['minor'] . $coreVersionParts['point'];

		foreach($current as $c){
			/** @var $c Component_2_1 */
			$n = $c->getKeyName();

			$parts = Core::VersionSplit($c->getVersion());

			if($n == 'core'){
				$core = array(
					'name' => $n,
					'title' => $c->getName(),
					'version' => $c->getVersion(),
					'feature' => $parts['major'] . '.' . $parts['minor'],
					'source' => 'installed',
					'description' => $c->getDescription(),
					'provides' => $c->getProvides(),
					'requires' => $c->getRequires(),
					'location' => null,
					'status' => 'installed',
					'type' => 'core',
					'typetitle' => 'Core',
					'key' => null,
					'destdir' => $c->getBaseDir(),
				);
			}
			else{
				$components[$n] = array(
					'name' => $n,
					'title' => $c->getName(),
					'version' => $c->getVersion(),
					'feature' => $parts['major'] . '.' . $parts['minor'],
					'source' => 'installed',
					'description' => $c->getDescription(),
					'provides' => $c->getProvides(),
					'requires' => $c->getRequires(),
					'location' => null,
					'status' => 'installed',
					'type' => 'components',
					'typetitle' => 'Component ' . $c->getName(),
					'key' => null,
					'destdir' => $c->getBaseDir(),
				);
			}
		}

		foreach(Core::GetDisabledComponents() as $c){
			/** @var $c Component_2_1 */
			$n = $c->getKeyName();

			$parts = Core::VersionSplit($c->getVersion());

			$components[$n] = array(
				'name' => $n,
				'title' => $c->getName(),
				'version' => $c->getVersion(),
				'feature' => $parts['major'] . '.' . $parts['minor'],
				'source' => 'installed',
				'description' => $c->getDescription(),
				'provides' => $c->getProvides(),
				'requires' => $c->getRequires(),
				'location' => null,
				'status' => 'disabled',
				'type' => 'components',
				'typetitle' => 'Component ' . $c->getName(),
				'key' => null,
				'destdir' => $c->getBaseDir(),
			);
		}

		// And repeat for the themes.
		// I need to do a check if they exist because if called from the installer, it may not.
		if(class_exists('ThemeHandler')){
			$currentthemes = ThemeHandler::GetAllThemes();
			if($currentthemes === null) $currentthemes = array();
		}
		else{
			$currentthemes = array();
		}

		foreach($currentthemes as $t){
			/** @var $t Theme */
			$n = $t->getKeyName();

			$parts = Core::VersionSplit($t->getVersion());

			$themes[$n] = array(
				'name' => $n,
				'title' => $t->getName(),
				'version' => $t->getVersion(),
				'feature' => $parts['major'] . '.' . $parts['minor'],
				'source' => 'installed',
				'description' => $t->getDescription(),
				'location' => null,
				'status' => 'installed',
				'type' => 'themes',
				'typetitle' => 'Theme ' . $t->getName(),
				'key' => null,
				'destdir' => $t->getBaseDir(),
			);
		}

		// Now, look up components from all the updates sites.
		// If the system isn't installed yet, then this will not be found.  Just use a blank array.
		if(class_exists('UpdateSiteModel')){
			$updatesites = UpdateSiteModel::Find();
		}
		else{
			$updatesites = array();
		}


		foreach($updatesites as $site){

			if(!$site->isValid()) continue;

			++$sitecount;
			$file = $site->getFile();

			$repoxml = new RepoXML();
			$repoxml->loadFromFile($file);
			$rootpath = dirname($file->getFilename()) . '/';

			foreach($repoxml->getPackages() as $pkg){
				/** @var $pkg PackageXML */
				// Already installed and is up to date, don't do anything.
				//if($pkg->isCurrent()) continue;

				$n = str_replace(' ', '-', strtolower($pkg->getName()));
				$type = $pkg->getType();
				if($n == 'core') $type = 'core'; // Override the core, even though it is a component...
				++$pkgcount;

				switch($type){
					case 'core':
						$vers = $pkg->getVersion();

						// Only display the newest version available.
						if(!Core::VersionCompare($vers, $core['version'], 'gt')) continue;

						// Only display new feature versions if it's not frozen.
						$parts = Core::VersionSplit($pkg->getVersion());
						if($froze && $core['feature'] != $parts['major'] . '.' . $parts['minor']) continue;

						$core = array(
							'name' => $n,
							'title' => $pkg->getName(),
							'version' => $vers,
							'feature' => $parts['major'] . '.' . $parts['minor'],
							'source' => 'repo-' . $site->get('id'),
							'sourceurl' => $site->get('url'),
							'description' => $pkg->getDescription(),
							'provides' => $pkg->getProvides(),
							'requires' => $pkg->getRequires(),
							'location' => $pkg->getFileLocation(),
							'status' =>'update',
							'type' => 'core',
							'typetitle' => 'Core ',
							'key' => $pkg->getKey(),
							'destdir' => ROOT_PDIR,
						);
						break;
					case 'component':
						$vers  = $pkg->getVersion();
						$parts = Core::VersionSplit($pkg->getVersion());
						$packagedWithVersion = $pkg->getRootDOM()->getAttribute('packager');

						if($packagedWithVersion && Core::VersionCompare($packagedWithVersion, $coreVersion, '>')){
							// Skip any package created with a newer version of Core than what is currently installed!
							continue;
						}

						// Is it already loaded in the list?
						if(isset($components[$n])){

							if(strpos($vers, '~bpo') !== false && strpos($vers, $backportVersion) === false){
								// Skip back ported versions not specifically for this version of Core.
								// This will check and see if the string ~bpo is present,
								// and when it is, enforce that it matches exactly this version of Core.
								continue;
							}

							// I only want the newest version.
							if(!Core::VersionCompare($vers, $components[$n]['version'], 'gt')){
								continue;
							}

							// Only display new feature versions if it's not frozen.
							if(
								$froze &&
								$components[$n]['status'] == 'installed' &&
								$components[$n]['feature'] != $parts['major'] . '.' . $parts['minor']
							){
								continue;
							}
						}

						// If it's available in the core, it's an update... otherwise it's new.
						$status = Core::GetComponent($n) ? 'update' : 'new';

						$components[$n] = array(
							'name' => $n,
							'title' => $pkg->getName(),
							'version' => $vers,
							'feature' => $parts['major'] . '.' . $parts['minor'],
							'source' => 'repo-' . $site->get('id'),
							'sourceurl' => $site->get('url'),
							'description' => $pkg->getDescription(),
							'provides' => $pkg->getProvides(),
							'requires' => $pkg->getRequires(),
							'location' => $pkg->getFileLocation(),
							'status' => $status,
							'type' => 'components',
							'typetitle' => 'Component ' . $pkg->getName(),
							'key' => $pkg->getKey(),
							'destdir' => ROOT_PDIR . 'components/' . $n . '/',
						);
						break;
					case 'theme':
						$vers = $pkg->getVersion();
						$parts = Core::VersionSplit($pkg->getVersion());

						// Is it already loaded in the list?
						if(isset($themes[$n])){
							// I only want the newest version.
							if(!Core::VersionCompare($vers, $themes[$n]['version'], 'gt')) continue;

							// Only display new feature versions if it's not frozen.
							if(
								$froze &&
								$themes[$n]['status'] == 'installed' &&
								$themes[$n]['feature'] != $parts['major'] . '.' . $parts['minor']
							){
								continue;
							}
						}

						$status = ThemeHandler::GetTheme($n) ? 'update' : 'new';

						$themes[$n] = array(
							'name' => $n,
							'title' => $pkg->getName(),
							'version' => $vers,
							'feature' => $parts['major'] . '.' . $parts['minor'],
							'source' => 'repo-' . $site->get('id'),
							'sourceurl' => $site->get('url'),
							'description' => $pkg->getDescription(),
							'location' => $pkg->getFileLocation(),
							'status' => $status,
							'type' => 'themes',
							'typetitle' => 'Theme ' . $pkg->getName(),
							'key' => $pkg->getKey(),
							'destdir' => ROOT_PDIR . 'themes/' . $n . '/',
						);
				}

				//var_dump($pkg->asPrettyXML()); die();
			}
		}

		// Give me the components in alphabetical order.
		ksort($components);
		ksort($themes);

		// Cache this for next pass.
		//$_SESSION['updaterhelper_getupdates'] = array();
		//$_SESSION['updaterhelper_getupdates']['data'] = array('core' => $core, 'components' => $components, 'themes' => $themes);
		//$_SESSION['updaterhelper_getupdates']['expire'] = time() + 60;

		return [
			'core'       => $core,
			'components' => $components,
			'themes'     => $themes,
			'sitecount'  => $sitecount,
			'pkgcount'   => $pkgcount,
		];
	}