HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/lib/class.upgrade.php
<?php
	/**
	* Base class for upgrade checks
	* @package IWP
	*/
	class Upgrade_base
	{

		/**
		* @var $error The last error message
		*/
		public $error = '';

		public $db = null;

		/**
		* CheckUpgrade stub function
		*
		* @return boolean returns false if we need to run the upgrade function
		*/
		public function CheckUpgrade()
		{
		}

		/**
		* Upgrade stub function
		*
		* @return void
		*/
		public function Upgrade_base(){
			$this->db = &$GLOBALS['AL_DB'];
		}

		/**
		* Check if a database table exists
		*
		* @param string $table The table name to check
		*
		* @return boolean If the table exists return true
		*/
		public function TableExists($table)
		{
			$query = "SHOW TABLES LIKE '".$table."'";
			$result = $this->db->FetchOne($query);
			// If there is a table with this name already we don't need to run this
			// part of the upgrade script

			// We have to convert the name to lower case before comparing since
			// if MySQL is on windows the tables are converted to lowercase
			// when they are returned from our sql statement
			if (iwp_strtolower($result) == iwp_strtolower($table)) {
				return true;
			} else {
				return false;
			}
		}

		/**
		* Check if a column exists in a table
		*
		* @param $table The table with the column we are checking for
		* @param $column The column to check for
		*
		* @return boolean If the column exists in the table return true
		*/
		public function ColumnExists($table, $column)
		{
			$query = 'SHOW COLUMNS FROM '.$table." LIKE '".$column."'";

			$result = $this->db->Query($query);
			$row = $this->db->Fetch($result);

			if ($row['Field'] == $column) {
				return true;
			} else {
				return false;
			}
		}

		/**
		* GetIndexInfo
		*
		* Get information about the indexes on $table and return an array with
		* this information
		*
		* @param string $table The name of the table to get information about the indexes for
		*
		* @return array The array containing the index information in the format
			$indexes = array (
				'indexname' => array (
					'unique' => true/false,
					'type' => btree/fulltext,
					'columns' = array (
						'field1',
						'field2',
						'field3',
					),
				),
				'index2name' => array (
					...
				),
			)
		*/
		public function GetIndexInfo($table)
		{
			$indexes = array();

			$query = 'SHOW INDEX FROM '.$table;
			$result = $this->db->Query($query);
			if ($result === false) {
				return array();
			}
			while ($row = $this->db->Fetch($result)) {
				if (!isset($indexes[$row['Key_name']])) {
					if (!isset($row['Index_type'])) {
						$row['Index_type'] = 'UNDEFINED';
					}

					$indexes[$row['Key_name']] = array (
						'unique' => ($row['Non_unique'] == 0),
						'type' => $row['Index_type'],
					);

					if (!isset($indexes[$row['Key_name']]['columns'])
					|| !is_array($indexes[$row['Key_name']]['columns'])) {
						$indexes[$row['Key_name']]['columns'] = array();
					}
				}

				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
			}
			return $indexes;
		}

		/**
		* IndexExists
		*
		* Check if an index exists on some table columns
		*
		* @param string $table The name of the table
		* @param array $columns The array of column names the index is on. Order counts.
		* @param bool $unique Is the index a unique index ?
		* @param string $type The type of index to check for (BTREE or FULLTEXT)
		*
		* @return bool Does the index exist as expected or not ?
		*/
		public function IndexExists($table, $columns, $unique=false, $type='BTREE')
		{
			$keymatches = array();
			$indexname = '';

			if (empty($table)) {
				$this->error = 'Table name is empty';
				return false;
			}

			if (empty($columns)) {
				$this->error = 'Columns is empty';
				return false;
			}

			if (!is_array($columns)) {
				$columns = (array)$columns;
			}

			if (!in_array($type, array('BTREE', 'FULLTEXT', 'UNDEFINED'))) {
				$this->error = 'Type of index was not an expected type';
				return false;
			}

			$indexes = $this->GetIndexInfo($table);

			if (empty($indexes)) {
				$this->error = 'Could not get index information';
				return false;
			}

			foreach ($indexes as $name => $index) {
				// Since MySQL can use the first part of the array, lets check
				// to see if the required index is already part of another index
				$slice = array_slice($index['columns'], 0, count($columns));

				// Check if the index is one we can use
				if (($index['type'] == $type || $index['type'] == 'UNDEFINED')
				&& $slice == $columns) {
					return true;
				}
			}
			return false;
		}

	}