Ejemplo n.º 1
0
	/**
	 * Internal function to lookup the saved data for a given component based on its name.
	 *
	 * Will return null if it doesn't exist or an array.
	 *
	 * @param string $componentname The name of the component to lookup
	 *
	 * @return array | null
	 */
	public static function _LookupComponentData($componentname) {
		if (self::$_DBCache === null) {
			self::$_DBCache = array();

			// Try to load the components
			try {
				$res = Core\Datamodel\Dataset::Init()->table('component')->select('*')->execute();
			}
				// But since this function is called during the installer, it might fail... that's acceptable.
			catch (DMI_Exception $e) {
				return false;
			}

			foreach ($res as $r) {
				$n                  = strtolower($r['name']);
				self::$_DBCache[$n] = $r;
			}
		}

		$componentname = strtolower($componentname);

		return (isset(self::$_DBCache[$componentname])) ? self::$_DBCache[$componentname] : null;
	}
Ejemplo n.º 2
0
	/**
	 * Load this record from the datastore.
	 *
	 * Generally not needed to be called directly, but can be if required.
	 */
	public function load() {

		// If there is no associated table, do not load anything.
		if (!self::GetTableName()) {
			return;
		}

		// I need to check the pks first.
		// If they're not set I can't load anything from the database.
		$i = self::GetIndexes();
		$s = self::GetSchema();

		$pri = (isset($i['primary'])) ? $i['primary'] : false;
		if($pri && !is_array($pri)) $pri = [$pri];

		$keys = [];
		if ($pri && sizeof($i['primary'])) {
			foreach ($pri as $k) {
				$v = $this->get($k);

				// 2012.12.15 cp - I am changing this from return to continue to support enterprise data in non-enterprise mode.
				// specifically, the page model.  Pages can be -1 for global or a specific ID for that site.
				// in non-multisite mode, there are no other sites, so -1 and 0 are synonymous even though it's a primary key.
				if ($v === null) continue;

				// Remember the PK's for the query lookup later on.
				$keys[$k] = $v;
			}
		}

		//if ($this->_cacheable) {
			//$cachekey = $this->_getCacheKey();
			//$cache    = Core::Cache()->get($cachekey);

			// do something if cache succeeds....
		//}

		// If the enterprise/multimode is set and enabled and there's a site column here,
		// that should be enforced at a low level.
		/** @noinspection PhpUndefinedClassInspection */
		if(
			isset($s['site']) &&
			$s['site']['type'] == Model::ATT_TYPE_SITE &&
			Core::IsComponentAvailable('multisite') &&
			MultiSiteHelper::IsEnabled() &&
			$this->get('site') === null
		){
			/** @noinspection PhpUndefinedClassInspection */
			$keys['site'] = MultiSiteHelper::GetCurrentSiteID();
		}


		$data = Core\Datamodel\Dataset::Init()
			->select('*')
			->table(self::GetTableName())
			->where($keys)
			->execute($this->interface);

		if ($data->num_rows) {
			$this->_loadFromRecord($data->current());
			$this->_exists = true;
		}
		else {
			$this->_exists = false;
		}

		return;
	}
	private function load() {
		if ($this->_loaded) return;

		// Load in all the data in the components table.
		try {
			$res            = Core\Datamodel\Dataset::Init()->table('component')->select('*')->execute();
			$this->_dbcache = array();
			foreach ($res as $r) {
				$n                  = strtolower($r['name']);
				$this->_dbcache[$n] = $r;
			}
		}
		catch (Exception $e) {
			//echo '<pre>' . $e->getTraceAsString() . '</pre>';
			return;
		}

		/*
				// Add all the libraries from the LibraryHandler.
				foreach(LibraryHandler::singleton()->librariesLoaded as $l){
					$ch->_libraries[$l->getName()] = $l->getVersion();
				}

				// Add any classes that come from libraries.
				$ch->_classes = array_merge($ch->_classes, LibraryHandler::singleton()->getClassList());
				 */

		// Load every component first.
		foreach ($this->_componentCache as $n => $c) {
			$c->load();

			// If the component is not in the initial dbcache, it must not be installed.
			// Keep it in the component cache, but do not try to load it just yet.
			if (!isset($this->_dbcache[$n])) {
				//unset($this->_componentCache[$n]);
				continue;
			}

			// Set the data from the loaded cache
			$c->_versionDB = $this->_dbcache[$n]['version'];
			$c->enabled    = ($this->_dbcache[$n]['enabled']);

			// First check before anything else is even done.... Did the user disable it?
			if (!$c->enabled) {
				//echo "Skipping " . $c->getName() . " because it is disabled<br/>";
				unset($this->_componentCache[$n]);
				continue;
			}

			//var_dump($c);
			// Doesn't contain a valid xml, just remove it.
			if (!$c->isValid()) {
				if (DEVELOPMENT_MODE) {
					echo 'Component ' . $c->getName() . ' appears to be invalid due to:<br/>' . $c->getErrors();
					//CAEUtils::AddMessage('Component ' . $c->name . ' appears to be invalid due to:<br/>' . $c->_invalidReason);
				}
				unset($this->_componentCache[$n]);
			}
		}

		// If the execution mode is CLI, ensure the CLI tools are installed!
		if (EXEC_MODE == 'CLI') {
			$cli_component = $this->getComponent('CLI');
			// CLI is bundled with the core.
			// How do you expect to use the CLI tools if they're not installed?	hmm???
			//if(!$cli_component) die("Cannot execute anything in CLI mode without the CLI component, please download that.\n");
			//if(!$cli_component->isInstalled()) $cli_component->install();
		}


		//echo "Loading...";
		// Now that I have a list of components available, copy them into a list of 
		//	components that are installed.

		$list = $this->_componentCache;

		do {
			$size = sizeof($list);
			foreach ($list as $n => $c) {

				// If it's loaded, register it and remove it from the list!
				if ($c->isInstalled() && $c->isLoadable() && $c->loadFiles()) {

					// Allow for on-the-fly package upgrading regardless of DEV mode or not.
					if ($c->needsUpdated()) {
						$c->upgrade();
					}

					$this->_registerComponent($c);
					unset($list[$n]);
					continue;
				}


				// Allow for on-the-fly package upgrading regardless of DEV mode or not.
				if ($c->isInstalled() && $c->needsUpdated() && $c->isLoadable()) {
					$c->upgrade();
					$c->loadFiles();
					$this->_registerComponent($c);
					unset($list[$n]);
					continue;
				}

				// Allow packages to be auto-installed if in DEV mode.
				// this should NEVER be enabled on production, due to the GIANT
				// security risk that it could potentially cause if someone manages
				// to get a rogue component.xml file on the filesystem. (in theory at least)
				if (!$c->isInstalled() && DEVELOPMENT_MODE && $c->isLoadable()) {
					// w00t
					$c->install();
					$c->loadFiles();
					$this->_registerComponent($c);
					unset($list[$n]);
					continue;
				}
			}
		}
		while ($size > 0 && ($size != sizeof($list)));

		// If dev mode is enabled, display a list of components installed but not loadable.
		if (DEVELOPMENT_MODE) {
			foreach ($list as $l) {
				// Ignore anything with the execmode different, those should be minor notices for debugging if anything.
				if ($l->error & Component_2_1::ERROR_WRONGEXECMODE) continue;

				$msg = 'Could not load installed component ' . $l->getName() . ' due to requirement failed.<br/>' . $l->getErrors();
				echo $msg . '<br/>';
				//Core::AddMessage($msg);
			}
		}


		$this->_loaded = true;
	}