Project

General

Profile

« Previous | Next » 

Revision 2120

Added by darkviper about 9 years ago

  1. framework/WbAdaptor some litte fixes
    + framework/WbDatabaseHelper contains now all maintenance methods from WbDatabase
    ! framework/WbDatabase all maintenance methods has been moved to framework/WbDatabaseHelper

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
10 Mar-2015 Build 2120 Manuela v.d.Decken(DarkViper)
15
# framework/WbAdaptor some litte fixes
16
+ framework/WbDatabaseHelper contains now all maintenance methods from WbDatabase
17
! framework/WbDatabase  all maintenance methods has been moved to framework/WbDatabaseHelper
14 18
28 Dec-2014 Build 2119 Manuela v.d.Decken(DarkViper)
15 19
# admin/login/ little fixes
16 20
28 Dec-2014 Build 2118 Manuela v.d.Decken(DarkViper)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.4');
54
if(!defined('REVISION')) define('REVISION', '2119');
54
if(!defined('REVISION')) define('REVISION', '2120');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/WbDatabase.php
47 47
		define('MYSQL_CLIENT_SSL',         2048);
48 48
	}
49 49

  
50
class WbDatabase {
50
class WbDatabase extends WbDatabaseHelper {
51 51

  
52 52
	private static $_oInstances = array();
53 53

  
......
113 113
		if ($url != '') {
114 114
		// parse URL and extract connection data
115 115
			$aIni = parse_url($url);
116
			$scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysql';
116
			$scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysqli';
117 117
			$hostname = isset($aIni['host']) ? $aIni['host'] : '';
118 118
			$username = isset($aIni['user']) ? $aIni['user'] : '';
119 119
			$password = isset($aIni['pass']) ? $aIni['pass'] : '';
......
144 144
			throw new WbDatabaseException('unable to connect \''.$scheme.'://'.$hostname.':'.$hostport.'\'');
145 145
		} else {
146 146
            if ($this->sCharset) {
147
                @mysqli_query($this->oDbHandle, 'SET NAMES \''.$this->sCharset.'\'');
147
                @mysqli_query($this->oDbHandle, 'SET NAMES '.$this->sCharset);
148
                mysqli_set_charset($this->oDbHandle, $this->sCharset);
148 149
            }
149 150
            $this->connected = true;
150 151
		}
......
328 329
	{
329 330
		return mysqli_insert_id($this->oDbHandle);
330 331
	}
331
/**
332
 * Alias for isField()
333
 * @deprecated from WB-2.8.5 and higher
334
 */
335
	public function field_exists($table_name, $field_name)
336
	{
337
		return $this->isField($table_name, $field_name);
338
	}
339
/*
340
 * @param string full name of the table (incl. TABLE_PREFIX)
341
 * @param string name of the field to seek for
342
 * @return bool true if field exists
343
 */
344
	public function isField($table_name, $field_name)
345
	{
346
		$sql = 'DESCRIBE `'.$table_name.'` `'.$field_name.'` ';
347
		$query = $this->doQuery($sql);
348
		return ($query->numRows() != 0);
349
	}
350
/**
351
 * Alias for isIndex()
352
 * @deprecated from WB-2.8.5 and higher
353
 */
354
	public function index_exists($table_name, $index_name, $number_fields = 0)
355
	{
356
		return $this->isIndex($table_name, $index_name, $number_fields = 0);
357
	}
358
/*
359
 * isIndex
360
 * @param string full name of the table (incl. TABLE_PREFIX)
361
 * @param string name of the index to seek for
362
 * @return bool true if field exists
363
 */
364
	public function isIndex($table_name, $index_name, $number_fields = 0)
365
	{
366
		$number_fields = intval($number_fields);
367
		$keys = 0;
368
		$sql = 'SHOW INDEX FROM `'.$table_name.'`';
369
		if (($res_keys = $this->doQuery($sql))) {
370
			while (($rec_key = $res_keys->fetchRow(MYSQL_ASSOC))) {
371
				if ( $rec_key['Key_name'] == $index_name ) {
372
					$keys++;
373
				}
374
			}
375 332

  
376
		}
377
		if ( $number_fields == 0 ) {
378
			return ($keys != $number_fields);
379
		} else {
380
			return ($keys == $number_fields);
381
		}
382
	}
383
/**
384
 * Alias for addField()
385
 * @deprecated from WB-2.8.5 and higher
386
 */
387
	public function field_add($table_name, $field_name, $description)
388
	{
389
		return $this->addField($table_name, $field_name, $description);
390
	}
391
/*
392
 * @param string full name of the table (incl. TABLE_PREFIX)
393
 * @param string name of the field to add
394
 * @param string describes the new field like ( INT NOT NULL DEFAULT '0')
395
 * @return bool true if successful, otherwise false and error will be set
396
 */
397
	public function addField($table_name, $field_name, $description)
398
	{
399
		if (!$this->isField($table_name, $field_name)) {
400
		// add new field into a table
401
			$sql = 'ALTER TABLE `'.$table_name.'` ADD '.$field_name.' '.$description.' ';
402
			$query = $this->doQuery($sql);
403
			$this->set_error(mysqli_error($this->oDbHandle));
404
			if (!$this->isError()) {
405
				return ( $this->isField($table_name, $field_name) ) ? true : false;
406
			}
407
		} else {
408
			$this->set_error('field \''.$field_name.'\' already exists');
409
		}
410
		return false;
411
	}
412
/**
413
 * Alias for modifyField()
414
 * @deprecated from WB-2.8.5 and higher
415
 */
416
	public function field_modify($table_name, $field_name, $description)
417
	{
418
		return $this->modifyField($table_name, $field_name, $description);
419
	}
420
/*
421
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
422
 * @param string $field_name: name of the field to add
423
 * @param string $description: describes the new field like ( INT NOT NULL DEFAULT '0')
424
 * @return bool: true if successful, otherwise false and error will be set
425
 */
426
	public function modifyField($table_name, $field_name, $description)
427
	{
428
		$retval = false;
429
		if ($this->isField($table_name, $field_name)) {
430
		// modify a existing field in a table
431
			$sql  = 'ALTER TABLE `'.$table_name.'` MODIFY `'.$field_name.'` '.$description;
432
			$retval = ( $this->doQuery($sql) ? true : false);
433
			$this->setError(mysqli_error($this->oDbHandle));
434
		}
435
		return $retval;
436
	}
437
/**
438
 * Alias for removeField()
439
 * @deprecated from WB-2.8.5 and higher
440
 */
441
	public function field_remove($table_name, $field_name)
442
	{
443
		return $this->removeField($table_name, $field_name);
444
	}
445
/*
446
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
447
 * @param string $field_name: name of the field to remove
448
 * @return bool: true if successful, otherwise false and error will be set
449
 */
450
	public function removeField($table_name, $field_name)
451
	{
452
		$retval = false;
453
		if ($this->isField($table_name, $field_name)) {
454
		// modify a existing field in a table
455
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP `'.$field_name.'`';
456
			$retval = ( $this->doQuery($sql, $this->oDbHandle) ? true : false );
457
		}
458
		return $retval;
459
	}
460
/**
461
 * Alias for addIndex()
462
 * @deprecated from WB-2.8.5 and higher
463
 */
464
    public function index_add($table_name, $index_name, $field_list, $index_type = 'KEY')
465
	{
466
		return $this->addIndex($table_name, $index_name, $field_list, $index_type);
467
	}
468
/*
469
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
470
 * @param string $index_name: name of the new index (empty string for PRIMARY)
471
 * @param string $field_list: comma seperated list of fields for this index
472
 * @param string $index_type: kind of index (PRIMARY, UNIQUE, KEY, FULLTEXT)
473
 * @return bool: true if successful, otherwise false and error will be set
474
 */
475
     public function addIndex($table_name, $index_name, $field_list, $index_type = 'KEY')
476
     {
477
        $retval = false;
478
        $field_list = explode(',', (str_replace(' ', '', $field_list)));
479
        $number_fields = sizeof($field_list);
480
        $field_list = '`'.implode('`,`', $field_list).'`';
481
        $index_name = $index_type == 'PRIMARY' ? $index_type : $index_name;
482
        if ( $this->isIndex($table_name, $index_name, $number_fields) ||
483
             $this->isIndex($table_name, $index_name))
484
        {
485
            $sql  = 'ALTER TABLE `'.$table_name.'` ';
486
            $sql .= 'DROP INDEX `'.$index_name.'`';
487
            if (!$this->doQuery($sql)) { return false; }
488
        }
489
        $sql  = 'ALTER TABLE `'.$table_name.'` ';
490
        $sql .= 'ADD '.$index_type.' ';
491
        $sql .= $index_type == 'PRIMARY' ? 'KEY ' : '`'.$index_name.'` ';
492
        $sql .= '( '.$field_list.' ); ';
493
        if ($this->doQuery($sql)) { $retval = true; }
494
        return $retval;
495
    }
496
/**
497
 * Alias for removeIndex()
498
 * @deprecated from WB-2.8.5 and higher
499
 */
500
	public function index_remove($table_name, $index_name)
501
	{
502
		return $this->removeIndex($table_name, $index_name);
503
	}
504
/*
505
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
506
 * @param string $field_name: name of the field to remove
507
 * @return bool: true if successful, otherwise false and error will be set
508
 */
509
	public function removeIndex($table_name, $index_name)
510
	{
511
		$retval = false;
512
		if ($this->isIndex($table_name, $index_name)) {
513
		// modify a existing field in a table
514
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP INDEX `'.$index_name.'`';
515
			$retval = ( $this->doQuery($sql) ? true : false );
516
		}
517
		return $retval;
518
	}
519
/**
520
 * Alias for importSql()
521
 * @deprecated from WB-2.8.5 and higher
522
 */
523
	public function SqlImport($sSqlDump,
524
	                          $sTablePrefix = '',
525
	                          $sAction      = 'install',
526
	                          $sEngine      = 'MyISAM',
527
	                          $sCollation   = 'utf8_unicode_ci')
528
	{
529
		return $this->importSql($sSqlDump, $sTablePrefix, $sAction, $sEngine, $sCollation);
530
	}
531

  
532
/**
533
 * retuns the type of the engine used for requested table
534
 * @param string $table name of the table, including prefix
535
 * @return boolean/string false on error, or name of the engine (myIsam/InnoDb)
536
 */
537
	public function getTableEngine($table)
538
	{
539
		$retVal = false;
540
		$mysqlVersion = mysqli_get_server_info($this->oDbHandle);
541
		$engineValue = (version_compare($mysqlVersion, '5.0') < 0) ? 'Type' : 'Engine';
542
		$sql = 'SHOW TABLE STATUS FROM `' . $this->sDbName . '` LIKE \'' . $table . '\'';
543
		if (($result = $this->doQuery($sql))) {
544
			if (($row = $result->fetchRow(MYSQL_ASSOC))) {
545
				$retVal = $row[$engineValue];
546
			}
547
		}
548
		return $retVal;
549
	}
550

  
551

  
552 333
} /// end of class database
553 334
// //////////////////////////////////////////////////////////////////////////////////// //
554 335
/**
......
600 381
 * @return object
601 382
 * @throws WbDatabaseException
602 383
 */
603
	function query($sStatement)
384
	public function query($sStatement)
604 385
	{
605 386
		$this->result = @mysqli_query($this->oDbHandle, $sStatement);
606 387
		if ($this->result === false) {
......
618 399
 * @return integer
619 400
 * @description number of returned records
620 401
 */
621
	function numRows()
402
	public function numRows()
622 403
	{
623 404
		return mysqli_num_rows($this->result);
624 405
	}
......
628 409
 * @return array
629 410
 * @description get current record and increment pointer
630 411
 */
631
	function fetchRow($typ = MYSQL_BOTH)
412
	public function fetchRow($typ = MYSQLI_BOTH)
632 413
	{
633 414
		return mysqli_fetch_array($this->result, $typ);
634 415
	}
......
639 420
 * @return object
640 421
 * @description get current record as an object and increment pointer
641 422
 */
642
	function fetchObject($sClassName = null, array $aParams = null)
423
	public function fetchObject($sClassName = null, array $aParams = null)
643 424
	{
644 425
		if ($sClassName === null || class_exists($sClassName)) {
645 426
			return mysqli_fetch_object($this->result, $sClassName, $aParams);
......
648 429
		}
649 430
	}
650 431
/**
432
 * fetchArray
433
 * @param  int $iType MYSQL_ASSOC(default) | MYSQL_BOTH | MYSQL_NUM
434
 * @return array of current record
435
 * @description get current record and increment pointer
436
 */
437
	public function fetchArray($iType = MYSQLI_ASSOC)
438
	{
439
        if ($iType < MYSQLI_ASSOC || $iType > MYSQLI_BOTH) {
440
            $iType = MYSQLI_ASSOC;
441
        }
442
		return mysqli_fetch_array($this->result, $iType);
443
	}
444
/**
445
 * fetchAll
446
 * @param  int $iType MYSQL_ASSOC(default) | MYSQL_NUM
447
 * @return array of rows
448
 * @description get all records of the result set
449
 */
450
    public function fetchAll($iType = MYSQL_ASSOC)
451
    {
452
        $iType = $iType != MYSQL_NUM ? MYSQL_ASSOC : MYSQL_NUM;
453
        return mysqli_fetch_all($this->result, $iType);
454
    }
455
/**
651 456
 * rewind
652 457
 * @return bool
653 458
 * @description set the recordpointer to the first record || false on error
654 459
 */
655
	function rewind()
460
	public function rewind()
656 461
	{
657 462
		return $this->seekRow(MYSQL_SEEK_FIRST);
658 463
	}
......
662 467
 * @return bool
663 468
 * @description set the pointer to the given record || false on error
664 469
 */
665
	function seekRow( $position = MYSQL_SEEK_FIRST )
470
	public function seekRow( $position = MYSQL_SEEK_FIRST )
666 471
	{
667 472
		$pmax = $this->numRows() - 1;
668 473
		$p = (($position < 0 || $position > $pmax) ? $pmax : $position);
......
673 478
 * @return bool
674 479
 * @description remove retult object from memeory
675 480
 */
676
	function freeResult()
481
	public function freeResult()
677 482
	{
678 483
		return mysqli_free_result($this->result);
679 484
	}
......
681 486
 * Get error
682 487
 * @return string || null if no error
683 488
 */
684
	function error()
489
	public function error()
685 490
	{
686 491
		if (isset($this->error)) {
687 492
			return $this->error;
......
704 509
	function db_update_key_value($table, $key, $value = '')
705 510
	{
706 511
		$oDb = WbDatabase::getInstance();
512
        $table = preg_replace('/^'.preg_quote($oDb->TablePrefix, '/').'/s', '', $table);
707 513
		if (!is_array($key)) {
708 514
			if (trim($key) != '') {
709 515
				$key = array( trim($key) => trim($value) );
branches/2.8.x/wb/framework/WbDatabaseHelper.php
1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
/**
19
 * WbDatabaseHelper.php
20
 *
21
 * @category     Core
22
 * @package      Core_database
23
 * @author       Manuela v.d.Decken <manuela@isteam.de>
24
 * @author       Dietmar W. <dietmar.woellbrink@websitebaker.org>
25
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.9
28
 * @revision     $Revision: 2105 $
29
 * @lastmodified $Date: 2014-11-24 18:41:13 +0100 (Mo, 24 Nov 2014) $
30
 * @deprecated   from WB version number 2.9
31
 * @description  Mysql database wrapper for use with websitebaker up to version 2.8.4
32
 */
33

  
34
abstract class WbDatabaseHelper {
35

  
36

  
37
/**
38
 * Alias for isField()
39
 * @deprecated from WB-2.8.5 and higher
40
 */
41
	public function field_exists($table_name, $field_name)
42
	{
43
		return $this->isField($table_name, $field_name);
44
	}
45
/*
46
 * @param string full name of the table (incl. TABLE_PREFIX)
47
 * @param string name of the field to seek for
48
 * @return bool true if field exists
49
 */
50
	public function isField($table_name, $field_name)
51
	{
52
		$sql = 'DESCRIBE `'.$table_name.'` `'.$field_name.'` ';
53
		$query = $this->doQuery($sql);
54
		return ($query->numRows() != 0);
55
	}
56
/**
57
 * Alias for isIndex()
58
 * @deprecated from WB-2.8.5 and higher
59
 */
60
	public function index_exists($table_name, $index_name, $number_fields = 0)
61
	{
62
		return $this->isIndex($table_name, $index_name, $number_fields = 0);
63
	}
64
/*
65
 * isIndex
66
 * @param string full name of the table (incl. TABLE_PREFIX)
67
 * @param string name of the index to seek for
68
 * @return bool true if field exists
69
 */
70
	public function isIndex($table_name, $index_name, $number_fields = 0)
71
	{
72
		$number_fields = intval($number_fields);
73
		$keys = 0;
74
		$sql = 'SHOW INDEX FROM `'.$table_name.'`';
75
		if (($res_keys = $this->doQuery($sql))) {
76
			while (($rec_key = $res_keys->fetchRow(MYSQL_ASSOC))) {
77
				if ( $rec_key['Key_name'] == $index_name ) {
78
					$keys++;
79
				}
80
			}
81

  
82
		}
83
		if ( $number_fields == 0 ) {
84
			return ($keys != $number_fields);
85
		} else {
86
			return ($keys == $number_fields);
87
		}
88
	}
89
/**
90
 * Alias for addField()
91
 * @deprecated from WB-2.8.5 and higher
92
 */
93
	public function field_add($table_name, $field_name, $description)
94
	{
95
		return $this->addField($table_name, $field_name, $description);
96
	}
97
/*
98
 * @param string full name of the table (incl. TABLE_PREFIX)
99
 * @param string name of the field to add
100
 * @param string describes the new field like ( INT NOT NULL DEFAULT '0')
101
 * @return bool true if successful, otherwise false and error will be set
102
 */
103
	public function addField($table_name, $field_name, $description)
104
	{
105
		if (!$this->isField($table_name, $field_name)) {
106
		// add new field into a table
107
			$sql = 'ALTER TABLE `'.$table_name.'` ADD '.$field_name.' '.$description.' ';
108
			$query = $this->doQuery($sql);
109
			$this->set_error(mysqli_error($this->oDbHandle));
110
			if (!$this->isError()) {
111
				return ( $this->isField($table_name, $field_name) ) ? true : false;
112
			}
113
		} else {
114
			$this->set_error('field \''.$field_name.'\' already exists');
115
		}
116
		return false;
117
	}
118
/**
119
 * Alias for modifyField()
120
 * @deprecated from WB-2.8.5 and higher
121
 */
122
	public function field_modify($table_name, $field_name, $description)
123
	{
124
		return $this->modifyField($table_name, $field_name, $description);
125
	}
126
/*
127
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
128
 * @param string $field_name: name of the field to add
129
 * @param string $description: describes the new field like ( INT NOT NULL DEFAULT '0')
130
 * @return bool: true if successful, otherwise false and error will be set
131
 */
132
	public function modifyField($table_name, $field_name, $description)
133
	{
134
		$retval = false;
135
		if ($this->isField($table_name, $field_name)) {
136
		// modify a existing field in a table
137
			$sql  = 'ALTER TABLE `'.$table_name.'` MODIFY `'.$field_name.'` '.$description;
138
			$retval = ( $this->doQuery($sql) ? true : false);
139
			$this->setError(mysqli_error($this->oDbHandle));
140
		}
141
		return $retval;
142
	}
143
/**
144
 * Alias for removeField()
145
 * @deprecated from WB-2.8.5 and higher
146
 */
147
	public function field_remove($table_name, $field_name)
148
	{
149
		return $this->removeField($table_name, $field_name);
150
	}
151
/*
152
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
153
 * @param string $field_name: name of the field to remove
154
 * @return bool: true if successful, otherwise false and error will be set
155
 */
156
	public function removeField($table_name, $field_name)
157
	{
158
		$retval = false;
159
		if ($this->isField($table_name, $field_name)) {
160
		// modify a existing field in a table
161
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP `'.$field_name.'`';
162
			$retval = ( $this->doQuery($sql, $this->oDbHandle) ? true : false );
163
		}
164
		return $retval;
165
	}
166
/**
167
 * Alias for addIndex()
168
 * @deprecated from WB-2.8.5 and higher
169
 */
170
    public function index_add($table_name, $index_name, $field_list, $index_type = 'KEY')
171
	{
172
		return $this->addIndex($table_name, $index_name, $field_list, $index_type);
173
	}
174
/*
175
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
176
 * @param string $index_name: name of the new index (empty string for PRIMARY)
177
 * @param string $field_list: comma seperated list of fields for this index
178
 * @param string $index_type: kind of index (PRIMARY, UNIQUE, KEY, FULLTEXT)
179
 * @return bool: true if successful, otherwise false and error will be set
180
 */
181
     public function addIndex($table_name, $index_name, $field_list, $index_type = 'KEY')
182
     {
183
        $retval = false;
184
        $field_list = explode(',', (str_replace(' ', '', $field_list)));
185
        $number_fields = sizeof($field_list);
186
        $field_list = '`'.implode('`,`', $field_list).'`';
187
        $index_name = $index_type == 'PRIMARY' ? $index_type : $index_name;
188
        if ( $this->isIndex($table_name, $index_name, $number_fields) ||
189
             $this->isIndex($table_name, $index_name))
190
        {
191
            $sql  = 'ALTER TABLE `'.$table_name.'` ';
192
            $sql .= 'DROP INDEX `'.$index_name.'`';
193
            if (!$this->doQuery($sql)) { return false; }
194
        }
195
        $sql  = 'ALTER TABLE `'.$table_name.'` ';
196
        $sql .= 'ADD '.$index_type.' ';
197
        $sql .= $index_type == 'PRIMARY' ? 'KEY ' : '`'.$index_name.'` ';
198
        $sql .= '( '.$field_list.' ); ';
199
        if ($this->doQuery($sql)) { $retval = true; }
200
        return $retval;
201
    }
202
/**
203
 * Alias for removeIndex()
204
 * @deprecated from WB-2.8.5 and higher
205
 */
206
	public function index_remove($table_name, $index_name)
207
	{
208
		return $this->removeIndex($table_name, $index_name);
209
	}
210
/*
211
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
212
 * @param string $field_name: name of the field to remove
213
 * @return bool: true if successful, otherwise false and error will be set
214
 */
215
	public function removeIndex($table_name, $index_name)
216
	{
217
		$retval = false;
218
		if ($this->isIndex($table_name, $index_name)) {
219
		// modify a existing field in a table
220
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP INDEX `'.$index_name.'`';
221
			$retval = ( $this->doQuery($sql) ? true : false );
222
		}
223
		return $retval;
224
	}
225
/**
226
 * Alias for importSql()
227
 * @deprecated from WB-2.8.5 and higher
228
 */
229
	public function SqlImport($sSqlDump,
230
	                          $sTablePrefix = '',
231
	                          $sAction      = 'install',
232
	                          $sEngine      = 'MyISAM',
233
	                          $sCollation   = 'utf8_unicode_ci')
234
	{
235
		return $this->importSql($sSqlDump, $sTablePrefix, $sAction, $sEngine, $sCollation);
236
	}
237

  
238
/**
239
 * retuns the type of the engine used for requested table
240
 * @param string $table name of the table, including prefix
241
 * @return boolean/string false on error, or name of the engine (myIsam/InnoDb)
242
 */
243
	public function getTableEngine($table)
244
	{
245
		$retVal = false;
246
		$mysqlVersion = mysqli_get_server_info($this->oDbHandle);
247
		$engineValue = (version_compare($mysqlVersion, '5.0') < 0) ? 'Type' : 'Engine';
248
		$sql = 'SHOW TABLE STATUS FROM `' . $this->sDbName . '` LIKE \'' . $table . '\'';
249
		if (($result = $this->doQuery($sql))) {
250
			if (($row = $result->fetchRow(MYSQL_ASSOC))) {
251
				$retVal = $row[$engineValue];
252
			}
253
		}
254
		return $retVal;
255
	}
256

  
257
}
258

  
259
// end of class WbDatabaseHelper
branches/2.8.x/wb/framework/WbAdaptor.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_package
25
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
......
35 35
class WbAdaptor {
36 36

  
37 37
/** active instance */	
38
	protected static $_oInstance = null;
38
	protected static $oInstance = null;
39 39
/** array hold settings */	
40
	protected $_aSys = array();
40
	protected $aProperties = array();
41
/**  */
42
    protected $aObjects = array('Db' => null, 'Trans' => null, 'App' => null);
43
/** vars which             */
44
    protected $aReservedVars = array('Db', 'Trans', 'App');
41 45
/** constructor */
42 46
	protected function __construct() 
43 47
	{
44
		$this->_aSys = array('System' => array(), 'Request' => array());
48
		$this->aProperties = array('System' => array(), 'Request' => array());
45 49
	}
46 50
/**
47 51
 * Get active instance 
......
49 53
 */
50 54
	public static function getInstance()
51 55
	{
52
		if(self::$_oInstance == null) {
56
		if(self::$oInstance == null) {
53 57
			$c = __CLASS__;
54
			self::$_oInstance = new $c();
58
			self::$oInstance = new $c();
55 59
			
56 60
		}
57
		return self::$_oInstance;
61
		return self::$oInstance;
58 62
	}
59 63
/**
64
 * set the global database object
65
 * @param WbDatabase $oDb
66
 */
67
    public function setDatabase(WbDatabase $oDb)
68
    {
69
        $this->aObjects['Db'] = $oDb;
70
        return true;
71
    }
72
/**
73
 * set the global translation object
74
 * @param Translate $oTrans
75
 */
76
    public function setTranslate(Translate $oTrans)
77
    {
78
        $this->aObjects['Trans'] = $oTrans;
79
        return true;
80
    }
81
/**
82
 * set the global application object
83
 * @param wb $oApp
84
 */
85
    public function setApplication(wb $oApp)
86
    {
87
        $this->aObjects['App'] = $oApp;
88
    }
89
/**
60 90
 * handle unknown properties
61 91
 * @param string name of the property
62 92
 * @param mixed value to set
......
64 94
 */	
65 95
	public function __set($name, $value) 
66 96
	{
67
		throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
97
        if (array_key_exists($name, $this->aProperties['System'])) {
98
            throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
99
        } else {
100
            $this->aProperties['Request'][$name] = $value;
101
        }
68 102
	}
69 103
/**
70 104
 * Get value of a variable
......
73 107
 */	
74 108
	public function __get($sVarname)
75 109
	{
76
		if( isset($this->_aSys['Request'][$sVarname])) {
77
			return $this->_aSys['Request'][$sVarname];
78
		}elseif( isset($this->_aSys['System'][$sVarname])) {
79
			return $this->_aSys['System'][$sVarname];
80
		}elseif( isset($this->_aSys[$sVarname])) {
81
			return $this->_aSys[$sVarname];
82
		}else {
83
			return null;
110
        if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
111
            return $this->aObjects[$sVarname];
112
        }
113
        if (isset($this->aProperties['System'][$sVarname])) {
114
            return $this->aProperties['System'][$sVarname];
115
        } elseif ( isset($this->aProperties['Request'][$sVarname])) {
116
            return $this->aProperties['Request'][$sVarname];
117
        } else {
118
            return null;
84 119
		}
85 120
	}
86 121
/**
......
90 125
 */	
91 126
	public function __isset($sVarname)
92 127
	{
93
		$bRetval = (isset($this->_aSys['Request'][$sVarname]) ||
94
		            isset($this->_aSys['System'][$sVarname]) ||
95
		            isset($this->_aSys[$sVarname]));
128
        if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
129
            return true;
130
        }
131
		$bRetval = (isset($this->aProperties['System'][$sVarname]) ||
132
		            isset($this->aProperties['Request'][$sVarname]));
96 133
		return $bRetval;
97 134
	}
98 135
/**
......
100 137
 */	
101 138
	public function getWbConstants()
102 139
	{
103
		$this->_aSys = array('System' => array(), 'Request' => array());
140
    // first reinitialize arrays
141
		$this->aProperties = array(
142
            'System' => array(),
143
            'Request' => array()
144
        );
145
    // get all defined constants
104 146
		$aConsts = get_defined_constants(true);
105
		foreach($aConsts['user'] as $sKey=>$sVal)
106
		{
147
    // iterate all user defined constants
148
		foreach ($aConsts['user'] as $sKey=>$sVal) {
149
            if (in_array($sKey, $this->aReservedVars)) { continue; }
107 150
		// skip possible existing database constants
108 151
			if (preg_match('/^db_|^TABLE_PREFIX$/i', $sKey)) { continue; }
109
		// change all path items to trailing slash scheme
152
		// change all path items to trailing slash scheme and assign the new naming syntax
110 153
			switch($sKey):
154
                case 'DEBUG':
155
                    $this->aProperties['System']['Debug'] = intval($sVal);
156
                    $this->aProperties['System']['DebugLevel'] = intval($sVal);
157
                    break;
111 158
				case 'WB_URL': 
112 159
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
113 160
					$sKey = 'AppUrl';
114
					$this->_aSys['System'][$sKey] = $sVal; 
161
					$this->aProperties['System'][$sKey] = $sVal;
115 162
					break;
116 163
				case 'WB_REL':
117 164
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
118 165
					$sKey = 'AppRel';
119
					$this->_aSys['System'][$sKey] = $sVal; 
166
					$this->aProperties['System'][$sKey] = $sVal;
120 167
					break;
121 168
				case 'WB_PATH':
122 169
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
123 170
					$sKey = 'AppPath';
124
					$this->_aSys['System'][$sKey] = $sVal; 
171
					$this->aProperties['System'][$sKey] = $sVal;
125 172
					break;
126 173
				case 'ADMIN_URL':
127 174
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
128 175
					$sKey = 'AcpUrl';
129
					$this->_aSys['System'][$sKey] = $sVal; 
176
					$this->aProperties['System'][$sKey] = $sVal;
130 177
					break;
131 178
				case 'ADMIN_REL':
132 179
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
133 180
					$sKey = 'AcpRel';
134
					$this->_aSys['System'][$sKey] = $sVal; 
181
					$this->aProperties['System'][$sKey] = $sVal;
135 182
					break;
136 183
				case 'ADMIN_PATH':
137 184
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
138 185
					$sKey = 'AcpPath';
139
					$this->_aSys['System'][$sKey] = $sVal; 
186
					$this->aProperties['System'][$sKey] = $sVal;
140 187
					break;
141 188
				case 'THEME_URL':
142 189
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
143 190
					$sKey = 'ThemeUrl';
144
					$this->_aSys['Request'][$sKey] = $sVal; 
191
					$this->aProperties['Request'][$sKey] = $sVal;
145 192
					break;
146 193
				case 'THEME_REL':
147 194
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
148 195
					$sKey = 'ThemeRel';
149
					$this->_aSys['Request'][$sKey] = $sVal; 
196
					$this->aProperties['Request'][$sKey] = $sVal;
150 197
					break;
151 198
				case 'THEME_PATH':
152 199
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
153 200
					$sKey = 'ThemePath';
154
					$this->_aSys['Request'][$sKey] = $sVal; 
201
					$this->aProperties['Request'][$sKey] = $sVal;
155 202
					break;
156 203
				case 'TMP_PATH':
157 204
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
158 205
					$sKey = 'TempPath';
159
					$this->_aSys['System'][$sKey] = $sVal; 
206
					$this->aProperties['System'][$sKey] = $sVal;
160 207
					break;
161 208
				case 'ADMIN_DIRECTORY':
162 209
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
163 210
					$sKey = 'AcpDir';
164
					$this->_aSys['System'][$sKey] = $sVal; 
211
					$this->aProperties['System'][$sKey] = $sVal;
165 212
					break;
166 213
				case 'DOCUMENT_ROOT':
167 214
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
168 215
					$sKey = 'DocumentRoot';
169
					$this->_aSys['System'][$sKey] = $sVal; 
216
					$this->aProperties['System'][$sKey] = $sVal;
170 217
					break;
171 218
				case 'PAGES_DIRECTORY':
172 219
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
173 220
					$sVal = $sVal=='/' ? '' : $sVal;
174 221
					$sKey = 'PagesDir';
175
					$this->_aSys['System'][$sKey] = $sVal; 
222
					$this->aProperties['System'][$sKey] = $sVal;
176 223
					break;
177 224
				case 'MEDIA_DIRECTORY':
178 225
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
179 226
					$sKey = 'MediaDir';
180
					$this->_aSys['System'][$sKey] = $sVal; 
227
					$this->aProperties['System'][$sKey] = $sVal;
181 228
					break;
182 229
				case 'DEFAULT_TEMPLATE':
183
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
230
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
184 231
					$sKey = 'DefaultTemplate';
185
					$this->_aSys['Request'][$sKey] = $sVal; 
232
					$this->aProperties['System'][$sKey] = $sVal;
186 233
					break;
187 234
				case 'TEMPLATE':
188
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
235
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
189 236
					$sKey = 'Template';
190
					$this->_aSys['Request'][$sKey] = $sVal;
237
					$this->aProperties['Request'][$sKey] = $sVal;
191 238
					break;
192 239
				case 'DEFAULT_THEME':
193
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
240
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
194 241
					$sKey = 'DefaultTheme';
195
					$this->_aSys['Request'][$sKey] = $sVal; 
242
					$this->aProperties['System'][$sKey] = $sVal;
243
					$this->aProperties['Request']['Theme'] = trim($sVal, '/');
196 244
					break;
197 245
				case 'OCTAL_FILE_MODE':
198 246
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
199 247
					$sKey = 'OctalFileMode';
200
					$this->_aSys['Request'][$sKey] = $sVal; 
248
					$this->aProperties['System']['OctalFileMode'] = $sVal;
249
					$this->aProperties['System']['FileModeOctal'] = $sVal;
201 250
					break;
202 251
				case 'OCTAL_DIR_MODE':
203 252
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
204 253
					$sKey = 'OctalDirMode';
205
					$this->_aSys['Request'][$sKey] = $sVal; 
254
					$this->aProperties['System']['OctalDirMode'] = $sVal;
255
					$this->aProperties['System']['DirModeOctal'] = $sVal;
206 256
					break;
207 257
				case 'WB_VERSION':
208 258
					$sKey = 'AppVersion';
209
					$this->_aSys['System'][$sKey] = $sVal; 
259
					$this->aProperties['System'][$sKey] = $sVal;
210 260
					break;
211 261
				case 'WB_REVISION':
212 262
					$sKey = 'AppRevision';
213
					$this->_aSys['System'][$sKey] = $sVal; 
263
					$this->aProperties['System'][$sKey] = $sVal;
214 264
					break;
215 265
				case 'WB_SP':
216 266
					$sKey = 'AppServicePack';
217
					$this->_aSys['System'][$sKey] = $sVal; 
267
					$this->aProperties['System'][$sKey] = $sVal;
218 268
					break;
219 269
                case 'PAGE_ICON_DIR':
220 270
                    $sKey = 'PageIconDir';
221 271
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
222
                    if (!isset($this->_aSys['Request']['Template'])) {
223
                        $this->_aSys['Request']['Template'] = $this->_aSys['Request']['DefaultTemplate'];
224
                    }
225
                    $sVal = str_replace('/*/', '/'.$this->_aSys['Request']['Template'], $sVal);
226
					$this->_aSys['System'][$sKey] = $sVal;
272
					$this->aProperties['Request'][$sKey] = $sVal;
227 273
                    break;
274
                case 'TEMPLATE_DIR':
275
                    break;
228 276
				default:
277
                    $aSysList = array(
278
                    // list of values which should be placed in ['System']
279
                        'DefaultCharset','DefaultDateFormat','DefaultLanguage','DefaultTimeFormat',
280
                        'DefaultTimezone','DevInfos'
281
                    );
282
                    // convert 'true' or 'false' strings into boolean
229 283
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
284
                    // reformatting constant names
230 285
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
231
					$this->_aSys['Request'][$sKey] = $sVal; 
286
                    if (in_array($sKey, $aSysList)) {
287
    					$this->aProperties['System'][$sKey] = $sVal;
288
                    } else {
289
                        $this->aProperties['Request'][$sKey] = $sVal;
290
                    }
232 291
					break;
233 292
			endswitch;
234
			$this->_aSys[$sKey] = $sVal;
235 293
		}
236
		$this->_aSys['AppName'] = 'WebsiteBaker';
237
		$this->_aSys['System']['AppName'] = 'WebsiteBaker';
238
		$this->_aSys['Request']['AppName'] = 'WebsiteBaker';
294
/* now set values which needs dependencies */
295
        if (!isset($this->aProperties['Request']['Template']) || $this->aProperties['Request']['Template'] == '') {
296
            $this->aProperties['Request']['Template'] = $this->DefaultTemplate;
297
        }
298
		$this->aProperties['System']['AppName'] = 'WebsiteBaker';
299
        if (isset($this->Template)) {
300
            $this->aProperties['Request']['TemplateDir']  = 'templates/'.$this->Template.'/';
301
            $this->aProperties['Request']['TemplateUrl']  = $this->AppUrl.'templates/'.$this->Template.'/';
302
            $this->aProperties['Request']['TemplatePath'] = $this->AppPath.'templates/'.$this->Template.'/';
303
        }
304
/* correct PageIconDir if necessary */
305
        $this->aProperties['Request']['PageIconDir'] = str_replace('/*/', '/'.$this->Template, $this->PageIconDir);
306

  
307
/* cleanup arrays */
308
        $this->aProperties['Request'] = array_diff_key(
309
            $this->aProperties['Request'],
310
            $this->aProperties['System']
311
        );
312

  
239 313
	}
314
// temporary method for testing purposes only
315
    public function showAll()
316
    {
317
        ksort($this->_aSys['System']);
318
        ksort($this->_aSys['Request']);
319
        return $this->_aSys;
320
    }
240 321

  
241 322
} // end of class WbAdaptor
242 323

  

Also available in: Unified diff