Beispiel #1
0
	/**
	 * Returns a database connection object. It caches the created objects for future use.
	 * @param array $options Options to use when instanciating the database connection
	 * @return AEAbstractDriver
	 */
	public static function &getDatabase($options, $unset = false)
	{
		static $instances;

		if (!isset( $instances )) {
			$instances = array();
		}

		$signature = serialize( $options );

		if($unset)
		{
			if (!empty($instances[$signature]))
			{
				$db =& $instances[$signature];
				$db = null;
				unset($instances[$signature]);
			}
			$null = null;
			return $null;
		}

		if (empty($instances[$signature]))
		{
			$driver		= array_key_exists('driver', $options) 		? $options['driver']	: '';
			$select		= array_key_exists('select', $options)		? $options['select']	: true;
			$database	= array_key_exists('database', $options)	? $options['database']	: null;

			$driver = preg_replace('/[^A-Z0-9_\.-]/i', '', $driver);
			if(empty($driver))
			{
				// No driver specified; try to guess
				$default_signature = serialize( AEPlatform::get_platform_database_options() );
				if($signature == $default_signature)
				{
					$driver = AEPlatform::get_default_database_driver(true);
				}
				else
				{
					$driver = AEPlatform::get_default_database_driver(false);
				}
			}
			else
			{
				// Make sure a full driver name was given
				if(substr($driver,0,2) != 'AE') $driver = 'AEDriver'.ucfirst($driver);
			}

			$instance	= new $driver($options);

			$instances[$signature] = & $instance;
		}

		return $instances[$signature];
	}
Beispiel #2
0
	public function __construct()
	{
		// This is a directory inclusion filter.
		$this->object	= 'db';
		$this->subtype	= 'inclusion';
		$this->method	= 'direct';
		$this->filter_name = 'PlatformSitedb';

		// Add a new record for the core Joomla! database
		// Get core database options
		$options = AEPlatform::get_platform_database_options();

		$host = $options['host'];
		$port	= NULL;
		$socket	= NULL;
		$targetSlot = substr( strstr( $host, ":" ), 1 );
		if (!empty( $targetSlot )) {
			// Get the port number or socket name
			if (is_numeric( $targetSlot ))
				$port	= $targetSlot;
			else
				$socket	= $targetSlot;

			// Extract the host name only
			$host = substr( $host, 0, strlen( $host ) - (strlen( $targetSlot ) + 1) );
			// This will take care of the following notation: ":3306"
			if($host == '')
				$host = 'localhost';
		}

		// This is the format of the database inclusion filters
		$entry = array(
			'host' => $host,
			'port' => is_null($socket) ? (is_null($port) ? '' : $port) : $socket,
			'username' => $options['user'],
			'password' => $options['password'],
			'database' => $options['database'],
			'prefix' => $options['prefix'],
			'dumpFile' => 'joomla.sql',
			'driver' => AEPlatform::get_default_database_driver(true)
		);


		// We take advantage of the filter class magic to inject our custom filters
		$configuration =& AEFactory::getConfiguration();

		$this->filter_data['[SITEDB]'] = $entry;

		parent::__construct();
	}
Beispiel #3
0
	/**
	 * Returns a database connection object. It's an alias of AECoreDatabase::getDatabase()
	 * @param array $options Options to use when instanciating the database connection
	 * @return AEAbstractDriver
	 */
	public static function unsetDatabase($options = null)
	{
		if(is_null($options))
		{
			$options = AEPlatform::get_platform_database_options();
		}
		$db =& AECoreDatabase::getDatabase($options);
		$db->close();
		AECoreDatabase::unsetDatabase($options);
	}
Beispiel #4
0
	/**
	 * Keeps a maximum number of "obsolete" records
	 */
	private function apply_obsolete_quotas()
	{
		$this->setStep('Applying quota limit on obsolete backup records');
		$this->setSubstep('');
		$registry =& AEFactory::getConfiguration();
		$limit = $registry->get('akeeba.quota.obsolete_quota', 0);
		$limit = (int)$limit;

		if($limit <= 0) return;

		$db =& AEFactory::getDatabase( AEPlatform::get_platform_database_options() );
		$query = 'SELECT `id` FROM #__ak_stats WHERE `status` = \'complete\' AND `filesexist` = 0 ORDER BY `id` DESC LIMIT '.$limit.',100000';
		$db->setQuery($query);
		$array = $db->loadResultArray();

		if(empty($array)) return;

		$ids = implode(',', $array);

		$query = "DELETE FROM #__ak_stats WHERE ".$db->nameQuote('id')." IN ($ids)";
		$db->setQuery($query);
		$db->query();
	}