| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | <?php | 
					
						
							|  |  |  |  | /** | 
					
						
							|  |  |  |  |  * Generation tools for DB_DataObject | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * PHP versions 4 and 5 | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |  * LICENSE: This source file is subject to version 3.01 of the PHP license | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |  * that is available through the world-wide-web at the following URI: | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |  * http://www.php.net/license/3_01.txt.  If you did not receive a copy of | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |  * the PHP License and are unable to obtain it through the web, please | 
					
						
							|  |  |  |  |  * send a note to license@php.net so we can mail you a copy immediately. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * @category   Database | 
					
						
							|  |  |  |  |  * @package    DB_DataObject | 
					
						
							|  |  |  |  |  * @author     Alan Knowles <alan@akbkhome.com> | 
					
						
							|  |  |  |  |  * @copyright  1997-2006 The PHP Group | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |  * @license    http://www.php.net/license/3_01.txt  PHP License 3.01 | 
					
						
							| 
									
										
										
										
											2017-07-10 13:25:04 +02:00
										 |  |  |  |  * @version    CVS: $Id: Generator.php 336719 2015-05-05 10:37:33Z alan_k $ | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |  * @link       http://pear.php.net/package/DB_DataObject | 
					
						
							|  |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /* | 
					
						
							|  |  |  |  | * Security Notes: | 
					
						
							|  |  |  |  | *   This class uses eval to create classes on the fly. | 
					
						
							|  |  |  |  | *   The table name and database name are used to check the database before writing the | 
					
						
							|  |  |  |  | *   class definitions, we now check for quotes and semi-colon's in both variables | 
					
						
							|  |  |  |  | *   so I cant see how it would be possible to generate code even if | 
					
						
							|  |  |  |  | *   for some crazy reason you took the classname and table name from User Input. | 
					
						
							|  |  |  |  | * | 
					
						
							|  |  |  |  | *   If you consider that wrong, or can prove it.. let me know! | 
					
						
							|  |  |  |  | */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |  * Config _$ptions | 
					
						
							| 
									
										
										
										
											2009-12-08 15:32:50 -05:00
										 |  |  |  |  * [DB_DataObject] | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |  * ; optional default = DB/DataObject.php | 
					
						
							|  |  |  |  |  * extends_location = | 
					
						
							|  |  |  |  |  * ; optional default = DB_DataObject | 
					
						
							|  |  |  |  |  * extends = | 
					
						
							|  |  |  |  |  * ; alter the extends field when updating a class (defaults to only replacing DB_DataObject) | 
					
						
							|  |  |  |  |  * generator_class_rewrite = ANY|specific_name   // default is DB_DataObject
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /** | 
					
						
							|  |  |  |  |  * Needed classes | 
					
						
							|  |  |  |  |  * We lazy load here, due to problems with the tests not setting up include path correctly. | 
					
						
							|  |  |  |  |  * FIXME! | 
					
						
							|  |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | class_exists('DB_DataObject') ? '' : /*require_once 'DB/DataObject.php'*/ require_once '../DataObject.php'; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | //require_once('Config.php');
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /** | 
					
						
							|  |  |  |  |  * Generator class | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * @package DB_DataObject | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | class DB_DataObject_Generator extends DB_DataObject | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     /* =========================================================== */ | 
					
						
							|  |  |  |  |     /*  Utility functions - for building db config files           */ | 
					
						
							|  |  |  |  |     /* =========================================================== */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * Array of table names | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var array | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public $tables; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * associative array table -> array of table row objects | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var array | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public $_definitions; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * active table being output | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var string | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public $table; // active tablename
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |     /** | 
					
						
							|  |  |  |  |      * links (generated) | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var array | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public $_fkeys; // active tablename
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |     /** | 
					
						
							|  |  |  |  |      * Output File was config object, now just string | 
					
						
							|  |  |  |  |      * Used to generate the Tables | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var    string outputbuffer for table definitions | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public $_newConfig; | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * class being extended (can be overridden by [DB_DataObject] extends=xxxx | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var    string | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public $_extends = 'DB_DataObject'; | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * line to use for require('DB/DataObject.php'); | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var    string | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public $_extendsFile = "DB/DataObject.php"; | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * class being generated | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @var    string | 
					
						
							|  |  |  |  |      * @access private | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public $_className; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * The 'starter' = call this to start the process | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  public | 
					
						
							|  |  |  |  |      * @return  none | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function start() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver']; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $databases = array(); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         foreach ($options as $k => $v) { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (substr($k, 0, 9) == 'database_') { | 
					
						
							|  |  |  |  |                 $databases[substr($k, 9)] = $v; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (isset($options['database'])) { | 
					
						
							|  |  |  |  |             if ($db_driver == 'DB') { | 
					
						
							|  |  |  |  |                 require_once 'DB.php'; | 
					
						
							|  |  |  |  |                 $dsn = DB::parseDSN($options['database']); | 
					
						
							|  |  |  |  |             } else { | 
					
						
							|  |  |  |  |                 require_once 'MDB2.php'; | 
					
						
							|  |  |  |  |                 $dsn = MDB2::parseDSN($options['database']); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (!isset($database[$dsn['database']])) { | 
					
						
							|  |  |  |  |                 $databases[$dsn['database']] = $options['database']; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($databases as $databasename => $database) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (!$database) { | 
					
						
							|  |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             $this->debug("CREATING FOR $databasename\n"); | 
					
						
							|  |  |  |  |             $class = get_class($this); | 
					
						
							|  |  |  |  |             $t = new $class; | 
					
						
							|  |  |  |  |             $t->_database_dsn = $database; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             $t->_database = $databasename; | 
					
						
							|  |  |  |  |             if ($db_driver == 'DB') { | 
					
						
							|  |  |  |  |                 require_once 'DB.php'; | 
					
						
							|  |  |  |  |                 $dsn = DB::parseDSN($database); | 
					
						
							|  |  |  |  |             } else { | 
					
						
							|  |  |  |  |                 require_once 'MDB2.php'; | 
					
						
							|  |  |  |  |                 $dsn = MDB2::parseDSN($database); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (($dsn['phptype'] == 'sqlite') && is_file($databasename)) { | 
					
						
							|  |  |  |  |                 $t->_database = basename($t->_database); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             $t->_createTableList(); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $t->_createForiegnKeys(); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             foreach (get_class_methods($class) as $method) { | 
					
						
							|  |  |  |  |                 if (substr($method, 0, 8) != 'generate') { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     continue; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 $this->debug("calling $method"); | 
					
						
							|  |  |  |  |                 $t->$method(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $this->debug("DONE\n\n"); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * Build a list of tables; | 
					
						
							|  |  |  |  |      * and store it in $this->tables and $this->_definitions[tablename]; | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  private | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @return none|object | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _createTableList() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         $this->_connect(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         $__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5]; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         $db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver']; | 
					
						
							|  |  |  |  |         $is_MDB2 = ($db_driver != 'DB') ? true : false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (is_object($__DB) && is_a($__DB, 'PEAR_Error')) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return (new PEAR)->raiseError($__DB->toString(), null, PEAR_ERROR_DIE); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!$is_MDB2) { | 
					
						
							|  |  |  |  |             // try getting a list of schema tables first. (postgres)
 | 
					
						
							|  |  |  |  |             $__DB->expectError(DB_ERROR_UNSUPPORTED); | 
					
						
							|  |  |  |  |             $this->tables = $__DB->getListOf('schema.tables'); | 
					
						
							|  |  |  |  |             $__DB->popExpect(); | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             /** | 
					
						
							|  |  |  |  |              * set portability and some modules to fetch the informations | 
					
						
							|  |  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $db_options = (new PEAR)->getStaticProperty('MDB2', 'options'); | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |             if (empty($db_options)) { | 
					
						
							|  |  |  |  |                 $__DB->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $__DB->loadModule('Manager'); | 
					
						
							|  |  |  |  |             $__DB->loadModule('Reverse'); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if ((empty($this->tables) || (is_object($this->tables) && is_a($this->tables, 'PEAR_Error')))) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             //if that fails fall back to clasic tables list.
 | 
					
						
							|  |  |  |  |             if (!$is_MDB2) { | 
					
						
							|  |  |  |  |                 // try getting a list of schema tables first. (postgres)
 | 
					
						
							|  |  |  |  |                 $__DB->expectError(DB_ERROR_UNSUPPORTED); | 
					
						
							|  |  |  |  |                 $this->tables = $__DB->getListOf('tables'); | 
					
						
							|  |  |  |  |                 $__DB->popExpect(); | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 $this->tables = $__DB->manager->listTables(); | 
					
						
							|  |  |  |  |                 $sequences = $__DB->manager->listSequences(); | 
					
						
							|  |  |  |  |                 foreach ($sequences as $k => $v) { | 
					
						
							|  |  |  |  |                     $this->tables[] = $__DB->getSequenceName($v); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (is_object($this->tables) && is_a($this->tables, 'PEAR_Error')) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return (new PEAR)->raiseError($this->tables->toString(), null, PEAR_ERROR_DIE); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // build views as well if asked to.
 | 
					
						
							|  |  |  |  |         if (!empty($options['build_views'])) { | 
					
						
							|  |  |  |  |             if (!$is_MDB2) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 $views = $__DB->getListOf(is_string($options['build_views']) ? | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $options['build_views'] : 'views'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } else { | 
					
						
							|  |  |  |  |                 $views = $__DB->manager->listViews(); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (is_object($views) && is_a($views, 'PEAR_Error')) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 return (new PEAR)->raiseError( | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     'Error getting Views (check the PEAR bug database for the fix to DB), ' . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $views->toString(), | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     null, | 
					
						
							|  |  |  |  |                     PEAR_ERROR_DIE | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 ); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $this->tables = array_merge($this->tables, $views); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // declare a temporary table to be filled with matching tables names
 | 
					
						
							|  |  |  |  |         $tmp_table = array(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($this->tables as $table) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (isset($options['generator_include_regex']) && | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 !preg_match($options['generator_include_regex'], $table)) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 $this->debug("SKIPPING (generator_include_regex) : $table"); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             if (isset($options['generator_exclude_regex']) && | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 preg_match($options['generator_exclude_regex'], $table)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $strip = empty($options['generator_strip_schema']) ? false : $options['generator_strip_schema']; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $strip = is_numeric($strip) ? (bool)$strip : $strip; | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $strip = (is_string($strip) && strtolower($strip) == 'true') ? true : $strip; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // postgres strip the schema bit from the
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (!empty($strip)) { | 
					
						
							|  |  |  |  |                 if (!is_string($strip) || preg_match($strip, $table)) { | 
					
						
							|  |  |  |  |                     $bits = explode('.', $table, 2); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                     $table = $bits[0]; | 
					
						
							|  |  |  |  |                     if (count($bits) > 1) { | 
					
						
							|  |  |  |  |                         $table = $bits[1]; | 
					
						
							|  |  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $this->debug("EXTRACTING : $table"); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 $__DB->quoteIdentifier($table) : $table; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (!$is_MDB2) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 $defs = $__DB->tableInfo($quotedTable); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 $defs = $__DB->reverse->tableInfo($quotedTable); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 // rename the length value, so it matches db's return.
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (is_object($defs) && is_a($defs, 'PEAR_Error')) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 // running in debug mode should pick this up as a big warning..
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 $this->debug("Error reading tableInfo: $table"); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 $this->raiseError('Error reading tableInfo, ' . $defs->toString()); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             // cast all definitions to objects - as we deal with that better.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             foreach ($defs as $def) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 if (!is_array($def)) { | 
					
						
							|  |  |  |  |                     continue; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |                 // rename the length value, so it matches db's return.
 | 
					
						
							|  |  |  |  |                 if (isset($def['length']) && !isset($def['len'])) { | 
					
						
							|  |  |  |  |                     $def['len'] = $def['length']; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 $this->_definitions[$table][] = (object)$def; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             // we find a matching table, just  store it into a temporary array
 | 
					
						
							|  |  |  |  |             $tmp_table[] = $table; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         // the temporary table array is now the right one (tables names matching
 | 
					
						
							|  |  |  |  |         // with regex expressions have been removed)
 | 
					
						
							|  |  |  |  |         $this->tables = $tmp_table; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         //print_r($this->_definitions);
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							|  |  |  |  |      * Auto generation of table data. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * it will output to db_oo_{database} the table definitions | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  private | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @return none|void | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function generateDefinitions() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         $this->debug("Generating Definitions file:        "); | 
					
						
							|  |  |  |  |         if (!$this->tables) { | 
					
						
							|  |  |  |  |             $this->debug("-- NO TABLES -- \n"); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //$this->_newConfig = new Config('IniFile');
 | 
					
						
							|  |  |  |  |         $this->_newConfig = ''; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($this->tables as $this->table) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $this->_generateDefinitionsTable(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $this->_connect(); | 
					
						
							|  |  |  |  |         // dont generate a schema if location is not set
 | 
					
						
							|  |  |  |  |         // it's created on the fly!
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (empty($options['schema_location']) && empty($options["ini_{$this->_database}"])) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         if (!empty($options['generator_no_ini'])) { // built in ini files..
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $base = @$options['schema_location']; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (isset($options["ini_{$this->_database}"])) { | 
					
						
							|  |  |  |  |             $file = $options["ini_{$this->_database}"]; | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             $file = "{$base}/{$this->_database}.ini"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!file_exists(dirname($file))) { | 
					
						
							|  |  |  |  |             require_once 'System.php'; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             (new System)->mkdir(array('-p', '-m', 0755, dirname($file))); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         $this->debug("Writing ini as {$file}\n"); | 
					
						
							|  |  |  |  |         //touch($file);
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         $tmpname = tempnam(session_save_path(), 'DataObject_'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         //print_r($this->_newConfig);
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         $fh = fopen($tmpname, 'w'); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         if (!$fh) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return (new PEAR)->raiseError( | 
					
						
							|  |  |  |  |                 "Failed to create temporary file: $tmpname\n" . | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 "make sure session.save_path is set and is writable\n", | 
					
						
							|  |  |  |  |                 null, | 
					
						
							|  |  |  |  |                 PEAR_ERROR_DIE | 
					
						
							|  |  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         fwrite($fh, $this->_newConfig); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         fclose($fh); | 
					
						
							|  |  |  |  |         $perms = file_exists($file) ? fileperms($file) : 0755; | 
					
						
							|  |  |  |  |         // windows can fail doing this. - not a perfect solution but otherwise it's getting really kludgy..
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (!@rename($tmpname, $file)) { | 
					
						
							|  |  |  |  |             unlink($file); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             rename($tmpname, $file); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         chmod($file, $perms); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         //$ret = $this->_newConfig->writeInput($file,false);
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         //if ((new PEAR)->isError($ret) ) {
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         //    return PEAR::raiseError($ret->message,null,PEAR_ERROR_DIE);
 | 
					
						
							|  |  |  |  |         // }
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * The table geneation part | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  private | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @return array|tabledef | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateDefinitionsTable() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         global $_DB_DATAOBJECT; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $defs = $this->_definitions[$this->table]; | 
					
						
							|  |  |  |  |         $this->_newConfig .= "\n[{$this->table}]\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $keys_out = "\n[{$this->table}__keys]\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $keys_out_primary = ''; | 
					
						
							|  |  |  |  |         $keys_out_secondary = ''; | 
					
						
							|  |  |  |  |         if (@$_DB_DATAOBJECT['CONFIG']['debug'] > 2) { | 
					
						
							|  |  |  |  |             echo "TABLE STRUCTURE FOR {$this->table}\n"; | 
					
						
							|  |  |  |  |             print_r($defs); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $DB = $this->getDatabaseConnection(); | 
					
						
							|  |  |  |  |         $dbtype = $DB->phptype; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $ret = array( | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             'table' => array(), | 
					
						
							|  |  |  |  |             'keys' => array(), | 
					
						
							|  |  |  |  |         ); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $ret_keys_primary = array(); | 
					
						
							|  |  |  |  |         $ret_keys_secondary = array(); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($defs as $t) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $n = 0; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $write_ini = true; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             switch (strtoupper($t->type)) { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 case 'INT': | 
					
						
							|  |  |  |  |                 case 'INT2':    // postgres
 | 
					
						
							|  |  |  |  |                 case 'INT4':    // postgres
 | 
					
						
							|  |  |  |  |                 case 'INT8':    // postgres
 | 
					
						
							|  |  |  |  |                 case 'SERIAL4': // postgres
 | 
					
						
							|  |  |  |  |                 case 'SERIAL8': // postgres
 | 
					
						
							|  |  |  |  |                 case 'INTEGER': | 
					
						
							|  |  |  |  |                 case 'TINYINT': | 
					
						
							|  |  |  |  |                 case 'SMALLINT': | 
					
						
							|  |  |  |  |                 case 'MEDIUMINT': | 
					
						
							|  |  |  |  |                 case 'BIGINT': | 
					
						
							|  |  |  |  |                     $type = DB_DATAOBJECT_INT; | 
					
						
							|  |  |  |  |                     if ($t->len == 1) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                         $type += DB_DATAOBJECT_BOOL; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     } | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'REAL': | 
					
						
							|  |  |  |  |                 case 'DOUBLE': | 
					
						
							|  |  |  |  |                 case 'DOUBLE PRECISION': // double precision (firebird)
 | 
					
						
							|  |  |  |  |                 case 'FLOAT': | 
					
						
							|  |  |  |  |                 case 'FLOAT4': // real (postgres)
 | 
					
						
							|  |  |  |  |                 case 'FLOAT8': // double precision (postgres)
 | 
					
						
							|  |  |  |  |                 case 'DECIMAL': | 
					
						
							|  |  |  |  |                 case 'MONEY':  // mssql and maybe others
 | 
					
						
							|  |  |  |  |                 case 'NUMERIC': | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case 'NUMBER': // oci8
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_INT; // should really by FLOAT!!! / MONEY...
 | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'YEAR': | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     $type = DB_DATAOBJECT_INT; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'BIT': | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case 'BOOL': | 
					
						
							|  |  |  |  |                 case 'BOOLEAN': | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_BOOL; | 
					
						
							|  |  |  |  |                     // postgres needs to quote '0'
 | 
					
						
							|  |  |  |  |                     if ($dbtype == 'pgsql') { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                         $type += DB_DATAOBJECT_STR; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     } | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'STRING': | 
					
						
							|  |  |  |  |                 case 'CHAR': | 
					
						
							|  |  |  |  |                 case 'VARCHAR': | 
					
						
							|  |  |  |  |                 case 'VARCHAR2': | 
					
						
							|  |  |  |  |                 case 'TINYTEXT': | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'ENUM': | 
					
						
							|  |  |  |  |                 case 'SET':         // not really but oh well
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |                 case 'POINT':       // mysql geometry stuff - not really string - but will do..
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'TIMESTAMPTZ': // postgres
 | 
					
						
							|  |  |  |  |                 case 'BPCHAR':      // postgres
 | 
					
						
							|  |  |  |  |                 case 'INTERVAL':    // postgres (eg. '12 days')
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'CIDR':        // postgres IP net spec
 | 
					
						
							|  |  |  |  |                 case 'INET':        // postgres IP
 | 
					
						
							|  |  |  |  |                 case 'MACADDR':     // postgress network Mac address.
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'INTEGER[]':   // postgres type
 | 
					
						
							|  |  |  |  |                 case 'BOOLEAN[]':   // postgres type
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_STR; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'TEXT': | 
					
						
							|  |  |  |  |                 case 'MEDIUMTEXT': | 
					
						
							|  |  |  |  |                 case 'LONGTEXT': | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 case '_TEXT':   //postgres (?? view ??)
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_TXT; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case 'DATE': | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case 'TIME': | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_TIME; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case 'DATETIME': | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'TIMESTAMP': // do other databases use this???
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $type = ($dbtype == 'mysql') ? | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                         DB_DATAOBJECT_MYSQLTIMESTAMP : | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                         DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'BLOB':       /// these should really be ignored!!!???
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |                 case 'TINYBLOB': | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'MEDIUMBLOB': | 
					
						
							|  |  |  |  |                 case 'LONGBLOB': | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |                 case 'CLOB': // oracle character lob support
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'BYTEA':   // postgres blob support..
 | 
					
						
							|  |  |  |  |                     $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_BLOB; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 default: | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     echo "*****************************************************************\n" . | 
					
						
							|  |  |  |  |                         "**               WARNING UNKNOWN TYPE                          **\n" . | 
					
						
							|  |  |  |  |                         "** Found column '{$t->name}', of type  '{$t->type}'            **\n" . | 
					
						
							|  |  |  |  |                         "** Please submit a bug, describe what type you expect this     **\n" . | 
					
						
							|  |  |  |  |                         "** column  to be                                               **\n" . | 
					
						
							|  |  |  |  |                         "** ---------POSSIBLE FIX / WORKAROUND -------------------------**\n" . | 
					
						
							|  |  |  |  |                         "** Try using MDB2 as the backend - eg set the config option    **\n" . | 
					
						
							|  |  |  |  |                         "** db_driver = MDB2                                            **\n" . | 
					
						
							|  |  |  |  |                         "*****************************************************************\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $write_ini = false; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $t->name)) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 echo "*****************************************************************\n" . | 
					
						
							|  |  |  |  |                     "**               WARNING COLUMN NAME UNUSABLE                  **\n" . | 
					
						
							|  |  |  |  |                     "** Found column '{$t->name}', of type  '{$t->type}'            **\n" . | 
					
						
							|  |  |  |  |                     "** Since this column name can't be converted to a php variable **\n" . | 
					
						
							|  |  |  |  |                     "** name, and the whole idea of mapping would result in a mess  **\n" . | 
					
						
							|  |  |  |  |                     "** This column has been ignored...                             **\n" . | 
					
						
							|  |  |  |  |                     "*****************************************************************\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (!strlen(trim($t->name))) { | 
					
						
							|  |  |  |  |                 continue; // is this a bug?
 | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (preg_match('/not[ _]null/i', $t->flags)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 $type += DB_DATAOBJECT_NOTNULL; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (in_array($t->name, array('null', 'yes', 'no', 'true', 'false'))) { | 
					
						
							|  |  |  |  |                 echo "*****************************************************************\n" . | 
					
						
							|  |  |  |  |                     "**                             WARNING                         **\n" . | 
					
						
							|  |  |  |  |                     "** Found column '{$t->name}', which is invalid in an .ini file **\n" . | 
					
						
							|  |  |  |  |                     "** This line will not be writen to the file - you will have    **\n" . | 
					
						
							|  |  |  |  |                     "** define the keys()/method manually.                          **\n" . | 
					
						
							|  |  |  |  |                     "*****************************************************************\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 $write_ini = false; | 
					
						
							|  |  |  |  |             } else { | 
					
						
							|  |  |  |  |                 $this->_newConfig .= "{$t->name} = $type\n"; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $ret['table'][$t->name] = $type; | 
					
						
							|  |  |  |  |             // i've no idea if this will work well on other databases?
 | 
					
						
							|  |  |  |  |             // only use primary key or nextval(), cause the setFrom blocks you setting all key items...
 | 
					
						
							|  |  |  |  |             // if no keys exist fall back to using unique
 | 
					
						
							|  |  |  |  |             //echo "\n{$t->name} => {$t->flags}\n";
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |             $secondary_key_match = isset($options['generator_secondary_key_match']) ? $options['generator_secondary_key_match'] : 'primary|unique'; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $m = array(); | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             if (preg_match('/(auto_increment|nextval\(([^)]*))/i', rawurldecode($t->flags), $m) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 || (isset($t->autoincrement) && ($t->autoincrement === true))) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 $sn = 'N'; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 if ($DB->phptype == 'pgsql' && !empty($m[2])) { | 
					
						
							|  |  |  |  |                     $sn = preg_replace('/[("]+/', '', $m[2]); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                     //echo urldecode($t->flags) . "\n" ;
 | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 // native sequences = 2
 | 
					
						
							|  |  |  |  |                 if ($write_ini) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                     $keys_out_primary .= "{$t->name} = $sn\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 $ret_keys_primary[$t->name] = $sn; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             } elseif ($secondary_key_match && preg_match('/(' . $secondary_key_match . ')/i', $t->flags)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 // keys.. = 1
 | 
					
						
							|  |  |  |  |                 $key_type = 'K'; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 if (!preg_match("/(primary)/i", $t->flags)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     $key_type = 'U'; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 if ($write_ini) { | 
					
						
							|  |  |  |  |                     $keys_out_secondary .= "{$t->name} = {$key_type}\n"; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 $ret_keys_secondary[$t->name] = $key_type; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $this->_newConfig .= $keys_out . (empty($keys_out_primary) ? $keys_out_secondary : $keys_out_primary); | 
					
						
							|  |  |  |  |         $ret['keys'] = empty($keys_out_primary) ? $ret_keys_secondary : $ret_keys_primary; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (@$_DB_DATAOBJECT['CONFIG']['debug'] > 2) { | 
					
						
							|  |  |  |  |             print_r(array("dump for {$this->table}", $ret)); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         return $ret; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * create the data for Foreign Keys (for links.ini) | 
					
						
							|  |  |  |  |      * Currenly only works with mysql / mysqli / posgtreas | 
					
						
							|  |  |  |  |      * to use, you must set option: generate_links=true | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @author Pascal Sch<EFBFBD>ni | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public function _createForiegnKeys() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         if (empty($options['generate_links'])) { | 
					
						
							|  |  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5]; | 
					
						
							|  |  |  |  |         if (!in_array($__DB->phptype, array('mysql', 'mysqli', 'pgsql'))) { | 
					
						
							|  |  |  |  |             echo "WARNING: cant handle non-mysql and pgsql introspection for defaults."; | 
					
						
							|  |  |  |  |             return null; // cant handle non-mysql introspection for defaults.
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $this->debug("generateForeignKeys: Start"); | 
					
						
							|  |  |  |  |         $DB = $this->getDatabaseConnection(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $fk = array(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         switch ($DB->phptype) { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case 'pgsql': | 
					
						
							|  |  |  |  |                 foreach ($this->tables as $this->table) { | 
					
						
							|  |  |  |  |                     $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($this->table) : $this->table; | 
					
						
							|  |  |  |  |                     $res =& $DB->query("SELECT
 | 
					
						
							|  |  |  |  |                                 pg_catalog.pg_get_constraintdef(r.oid, true) AS condef | 
					
						
							|  |  |  |  |                             FROM pg_catalog.pg_constraint r, | 
					
						
							|  |  |  |  |                                  pg_catalog.pg_class c | 
					
						
							|  |  |  |  |                             WHERE c.oid=r.conrelid | 
					
						
							|  |  |  |  |                                   AND r.contype = 'f' | 
					
						
							|  |  |  |  |                                   AND c.relname = '" . $quotedTable . "'");
 | 
					
						
							|  |  |  |  |                     if ((new PEAR)->isError($res)) { | 
					
						
							|  |  |  |  |                         die($res->getMessage()); | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { | 
					
						
							|  |  |  |  |                         $treffer = array(); | 
					
						
							|  |  |  |  |                         // this only picks up one of these.. see this for why: http://pear.php.net/bugs/bug.php?id=17049
 | 
					
						
							|  |  |  |  |                         preg_match( | 
					
						
							|  |  |  |  |                             "/FOREIGN KEY \((\w*)\) REFERENCES (\w*)\((\w*)\)/i", | 
					
						
							|  |  |  |  |                             $row['condef'], | 
					
						
							|  |  |  |  |                             $treffer | 
					
						
							|  |  |  |  |                         ); | 
					
						
							|  |  |  |  |                         if (!count($treffer)) { | 
					
						
							|  |  |  |  |                             continue; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         $fk[$this->table][$treffer[1]] = $treffer[2] . ":" . $treffer[3]; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case 'mysql': | 
					
						
							|  |  |  |  |             case 'mysqli': | 
					
						
							|  |  |  |  |             default: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 foreach ($this->tables as $this->table) { | 
					
						
							|  |  |  |  |                     $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($this->table) : $this->table; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     $res =& $DB->query('SHOW CREATE TABLE ' . $quotedTable); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     if ((new PEAR)->isError($res)) { | 
					
						
							|  |  |  |  |                         die($res->getMessage()); | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     $text = $res->fetchRow(DB_FETCHMODE_DEFAULT, 0); | 
					
						
							|  |  |  |  |                     $treffer = array(); | 
					
						
							|  |  |  |  |                     // Extract FOREIGN KEYS
 | 
					
						
							|  |  |  |  |                     preg_match_all( | 
					
						
							|  |  |  |  |                         "/FOREIGN KEY \(`(\w*)`\) REFERENCES `(\w*)` \(`(\w*)`\)/i", | 
					
						
							|  |  |  |  |                         $text[1], | 
					
						
							|  |  |  |  |                         $treffer, | 
					
						
							|  |  |  |  |                         PREG_SET_ORDER | 
					
						
							|  |  |  |  |                     ); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     if (!count($treffer)) { | 
					
						
							|  |  |  |  |                         continue; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     foreach ($treffer as $i => $tref) { | 
					
						
							|  |  |  |  |                         $fk[$this->table][$tref[1]] = $tref[2] . ":" . $tref[3]; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->_fkeys = $fk; | 
					
						
							|  |  |  |  |     return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * generate Foreign Keys (for links.ini) | 
					
						
							|  |  |  |  |      * Currenly only works with mysql / mysqli | 
					
						
							|  |  |  |  |      * to use, you must set option: generate_links=true | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @author Pascal Sch<EFBFBD>ni | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function generateForeignKeys() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         if (empty($options['generate_links'])) { | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5]; | 
					
						
							|  |  |  |  |         if (!in_array($__DB->phptype, array('mysql', 'mysqli', 'pgsql'))) { | 
					
						
							|  |  |  |  |             echo "WARNING: cant handle non-mysql and pgsql introspection for defaults."; | 
					
						
							|  |  |  |  |             return null; // cant handle non-mysql introspection for defaults.
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $this->debug("generateForeignKeys: Start"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $fk = $this->_fkeys; | 
					
						
							|  |  |  |  |         $links_ini = ""; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         foreach ($fk as $table => $details) { | 
					
						
							|  |  |  |  |             $links_ini .= "[$table]\n"; | 
					
						
							|  |  |  |  |             foreach ($details as $col => $ref) { | 
					
						
							|  |  |  |  |                 $links_ini .= "$col = $ref\n"; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             $links_ini .= "\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // dont generate a schema if location is not set
 | 
					
						
							|  |  |  |  |         // it's created on the fly!
 | 
					
						
							|  |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (!empty($options['schema_location'])) { | 
					
						
							|  |  |  |  |             $file = "{$options['schema_location']}/{$this->_database}.links.ini"; | 
					
						
							|  |  |  |  |         } elseif (isset($options["ini_{$this->_database}"])) { | 
					
						
							|  |  |  |  |             $file = preg_replace('/\.ini/', '.links.ini', $options["ini_{$this->_database}"]); | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             $this->debug("generateForeignKeys: SKIP - schema_location or ini_{database} was not set"); | 
					
						
							|  |  |  |  |             return null; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (!file_exists(dirname($file))) { | 
					
						
							|  |  |  |  |             mkdir(dirname($file), 0755, true); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->debug("Writing ini as {$file}\n"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //touch($file); // not sure why this is needed?
 | 
					
						
							|  |  |  |  |         $tmpname = tempnam(session_save_path(), 'DataObject_'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $fh = fopen($tmpname, 'w'); | 
					
						
							|  |  |  |  |         if (!$fh) { | 
					
						
							|  |  |  |  |             return (new PEAR)->raiseError( | 
					
						
							|  |  |  |  |                 "Failed to create temporary file: $tmpname\n" . | 
					
						
							|  |  |  |  |                 "make sure session.save_path is set and is writable\n", | 
					
						
							|  |  |  |  |                 null, | 
					
						
							|  |  |  |  |                 PEAR_ERROR_DIE | 
					
						
							|  |  |  |  |             ); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         fwrite($fh, $links_ini); | 
					
						
							|  |  |  |  |         fclose($fh); | 
					
						
							|  |  |  |  |         $perms = file_exists($file) ? fileperms($file) : 0755; | 
					
						
							|  |  |  |  |         // windows can fail doing this. - not a perfect solution but otherwise it's getting really kludgy..
 | 
					
						
							|  |  |  |  |         if (!@rename($tmpname, $file)) { | 
					
						
							|  |  |  |  |             unlink($file); | 
					
						
							|  |  |  |  |             rename($tmpname, $file); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         chmod($file, $perms); | 
					
						
							|  |  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /* | 
					
						
							|  |  |  |  |      * building the class files | 
					
						
							|  |  |  |  |      * for each of the tables output a file! | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function generateClasses() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         //echo "Generating Class files:        \n";
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         $this->_extends = empty($options['extends']) ? $this->_extends : $options['extends']; | 
					
						
							| 
									
										
										
										
											2017-07-10 13:25:04 +02:00
										 |  |  |  |         $this->_extendsFile = !isset($options['extends_location']) ? $this->_extendsFile : $options['extends_location']; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($this->tables as $this->table) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $this->table = trim($this->table); | 
					
						
							|  |  |  |  |             $this->classname = $this->getClassNameFromTableName($this->table); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $i = ''; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $outfilename = $this->getFileNameFromTableName($this->table); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $oldcontents = ''; | 
					
						
							|  |  |  |  |             if (file_exists($outfilename)) { | 
					
						
							|  |  |  |  |                 // file_get_contents???
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 $oldcontents = implode('', file($outfilename)); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $out = $this->_generateClassTable($oldcontents); | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $this->debug("writing $this->classname\n"); | 
					
						
							|  |  |  |  |             $tmpname = tempnam(session_save_path(), 'DataObject_'); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $fh = fopen($tmpname, "w"); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             if (!$fh) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 return (new PEAR)->raiseError( | 
					
						
							|  |  |  |  |                     "Failed to create temporary file: $tmpname\n" . | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                     "make sure session.save_path is set and is writable\n", | 
					
						
							|  |  |  |  |                     null, | 
					
						
							|  |  |  |  |                     PEAR_ERROR_DIE | 
					
						
							|  |  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             fputs($fh, $out); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             fclose($fh); | 
					
						
							|  |  |  |  |             $perms = file_exists($outfilename) ? fileperms($outfilename) : 0755; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // windows can fail doing this. - not a perfect solution but otherwise it's getting really kludgy..
 | 
					
						
							|  |  |  |  |             if (!@rename($tmpname, $outfilename)) { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 unlink($outfilename); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 rename($tmpname, $outfilename); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             chmod($outfilename, $perms); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         //echo $out;
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Convert a table name into a class name -> override this if you want a different mapping | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @access  public | 
					
						
							|  |  |  |  |      * @param $table | 
					
						
							|  |  |  |  |      * @return  string class name; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     public function getClassNameFromTableName($table) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         $class_prefix = empty($options['class_prefix']) ? '' : $options['class_prefix']; | 
					
						
							|  |  |  |  |         return $class_prefix . preg_replace('/[^A-Z0-9]/i', '_', ucfirst(trim($this->table))); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Convert a table name into a file name -> override this if you want a different mapping | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @access  public | 
					
						
							|  |  |  |  |      * @param $table | 
					
						
							|  |  |  |  |      * @return  string file name; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public function getFileNameFromTableName($table) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         $base = $options['class_location']; | 
					
						
							|  |  |  |  |         if (strpos($base, '%s') !== false) { | 
					
						
							|  |  |  |  |             $base = dirname($base); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (!file_exists($base)) { | 
					
						
							|  |  |  |  |             require_once 'System.php'; | 
					
						
							|  |  |  |  |             (new System)->mkdir(array('-p', $base)); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (strpos($options['class_location'], '%s') !== false) { | 
					
						
							|  |  |  |  |             $outfilename = sprintf( | 
					
						
							|  |  |  |  |                 $options['class_location'], | 
					
						
							|  |  |  |  |                 preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table)) | 
					
						
							|  |  |  |  |             ); | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             $outfilename = "{$base}/" . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table)) . ".php"; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         return $outfilename; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * The table class geneation part - single file. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  private | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @param string $input | 
					
						
							|  |  |  |  |      * @return none|string | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateClassTable($input = '') | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         // title = expand me!
 | 
					
						
							|  |  |  |  |         $foot = ""; | 
					
						
							|  |  |  |  |         $head = "<?php\n/**\n * Table Definition for {$this->table}\n"; | 
					
						
							|  |  |  |  |         $head .= $this->derivedHookPageLevelDocBlock(); | 
					
						
							|  |  |  |  |         $head .= " */\n"; | 
					
						
							|  |  |  |  |         $head .= $this->derivedHookExtendsDocBlock(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-10 13:25:04 +02:00
										 |  |  |  |         // requires - if you set extends_location = (blank) then no require line will be set
 | 
					
						
							|  |  |  |  |         // this can be used if you have an autoloader
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-10 13:25:04 +02:00
										 |  |  |  |         if (!empty($this->_extendsFile)) { | 
					
						
							|  |  |  |  |             $head .= "require_once '{$this->_extendsFile}';\n\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         // add dummy class header in...
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         // class
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $head .= $this->derivedHookClassDocBlock(); | 
					
						
							|  |  |  |  |         $head .= "class {$this->classname} extends {$this->_extends} \n{"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $body = "\n    ###START_AUTOCODE\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $body .= "    /* the code below is auto generated do not remove the above tag */\n\n"; | 
					
						
							|  |  |  |  |         // table
 | 
					
						
							| 
									
										
										
										
											2011-03-26 14:45:15 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $p = str_repeat(' ', max(2, (18 - strlen($this->table)))); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         $var = (substr(phpversion(), 0, 1) > 4) ? 'public' : 'var'; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $var = !empty($options['generator_var_keyword']) ? $options['generator_var_keyword'] : $var; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $body .= "    {$var} \$__table = '{$this->table}';  {$p}// table name\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         // if we are using the option database_{databasename} = dsn
 | 
					
						
							|  |  |  |  |         // then we should add var $_database = here
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         // as database names may not always match..
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |         if (empty($GLOBALS['_DB_DATAOBJECT']['CONFIG'])) { | 
					
						
							|  |  |  |  |             DB_DataObject::_loadConfig(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         // Only include the $_database property if the omit_database_var is unset or false
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 23:35:20 -04:00
										 |  |  |  |         if (isset($options["database_{$this->_database}"]) && empty($GLOBALS['_DB_DATAOBJECT']['CONFIG']['generator_omit_database_var'])) { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $p = str_repeat(' ', max(2, (16 - strlen($this->_database)))); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $body .= "    {$var} \$_database = '{$this->_database}';  {$p}// database name (used with database_{*} config)\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!empty($options['generator_novars'])) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $var = '//' . $var; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $defs = $this->_definitions[$this->table]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // show nice information!
 | 
					
						
							|  |  |  |  |         $connections = array(); | 
					
						
							|  |  |  |  |         $sets = array(); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:45:15 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($defs as $t) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             if (!strlen(trim($t->name))) { | 
					
						
							|  |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $t->name)) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 echo "*****************************************************************\n" . | 
					
						
							|  |  |  |  |                     "**               WARNING COLUMN NAME UNUSABLE                  **\n" . | 
					
						
							|  |  |  |  |                     "** Found column '{$t->name}', of type  '{$t->type}'            **\n" . | 
					
						
							|  |  |  |  |                     "** Since this column name can't be converted to a php variable **\n" . | 
					
						
							|  |  |  |  |                     "** name, and the whole idea of mapping would result in a mess  **\n" . | 
					
						
							|  |  |  |  |                     "** This column has been ignored...                             **\n" . | 
					
						
							|  |  |  |  |                     "*****************************************************************\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $pad = str_repeat(' ', max(2, (30 - strlen($t->name)))); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:45:15 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $length = empty($t->len) ? '' : '(' . $t->len . ')'; | 
					
						
							|  |  |  |  |             $flags = strlen($t->flags) ? (' ' . trim($t->flags)) : ''; | 
					
						
							|  |  |  |  |             $body .= "    {$var} \${$t->name}; {$pad}// {$t->type}{$length}{$flags}\n"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // can not do set as PEAR::DB table info doesnt support it.
 | 
					
						
							|  |  |  |  |             //if (substr($t->Type,0,3) == "set")
 | 
					
						
							|  |  |  |  |             //    $sets[$t->Field] = "array".substr($t->Type,3);
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $body .= $this->derivedHookVar($t, strlen($p)); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 14:45:15 -04:00
										 |  |  |  |         $body .= $this->derivedHookPostVar($defs); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         // THIS IS TOTALLY BORKED old FC creation
 | 
					
						
							|  |  |  |  |         // IT WILL BE REMOVED!!!!! in DataObjects 1.6
 | 
					
						
							|  |  |  |  |         // grep -r __clone * to find all it's uses
 | 
					
						
							|  |  |  |  |         // and replace them with $x = clone($y);
 | 
					
						
							|  |  |  |  |         // due to the change in the PHP5 clone design.
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         $static = 'static'; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (substr(phpversion(), 0, 1) < 5) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $body .= "\n"; | 
					
						
							|  |  |  |  |             $body .= "    /* ZE2 compatibility trick*/\n"; | 
					
						
							|  |  |  |  |             $body .= "    function __clone() { return \$this;}\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         // depricated - in here for BC...
 | 
					
						
							|  |  |  |  |         if (!empty($options['static_get'])) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             // simple creation tools ! (static stuff!)
 | 
					
						
							|  |  |  |  |             $body .= "\n"; | 
					
						
							|  |  |  |  |             $body .= "    /* Static get */\n"; | 
					
						
							|  |  |  |  |             $body .= "    $static  function staticGet(\$k,\$v=NULL) { " . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 "return DB_DataObject::staticGet('{$this->classname}',\$k,\$v = null); }\n"; | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         // generate getter and setter methods
 | 
					
						
							|  |  |  |  |         $body .= $this->_generateGetters($input); | 
					
						
							|  |  |  |  |         $body .= $this->_generateSetters($input); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         $body .= $this->_generateLinkMethods($input); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         /* | 
					
						
							|  |  |  |  |         theoretically there is scope here to introduce 'list' methods | 
					
						
							|  |  |  |  |         based up 'xxxx_up' column!!! for heiracitcal trees.. | 
					
						
							|  |  |  |  |         */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // set methods
 | 
					
						
							|  |  |  |  |         //foreach ($sets as $k=>$v) {
 | 
					
						
							|  |  |  |  |         //    $kk = strtoupper($k);
 | 
					
						
							|  |  |  |  |         //    $body .="    function getSets{$k}() { return {$v}; }\n";
 | 
					
						
							|  |  |  |  |         //}
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!empty($options['generator_no_ini'])) { | 
					
						
							|  |  |  |  |             $def = $this->_generateDefinitionsTable();  // simplify this!?
 | 
					
						
							|  |  |  |  |             $body .= $this->_generateTableFunction($def['table']); | 
					
						
							|  |  |  |  |             $body .= $this->_generateKeysFunction($def['keys']); | 
					
						
							|  |  |  |  |             $body .= $this->_generateSequenceKeyFunction($def); | 
					
						
							|  |  |  |  |             $body .= $this->_generateDefaultsFunction($this->table, $def['table']); | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         } elseif (!empty($options['generator_add_defaults'])) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // I dont really like doing it this way (adding another option)
 | 
					
						
							|  |  |  |  |             // but it helps on older projects.
 | 
					
						
							|  |  |  |  |             $def = $this->_generateDefinitionsTable();  // simplify this!?
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $body .= $this->_generateDefaultsFunction($this->table, $def['table']); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         $body .= $this->derivedHookFunctions($input); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $body .= "\n    /* the code above is auto generated do not remove the tag below */"; | 
					
						
							|  |  |  |  |         $body .= "\n    ###END_AUTOCODE\n"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // stubs..
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!empty($options['generator_add_validate_stubs'])) { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             foreach ($defs as $t) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 if (!strlen(trim($t->name))) { | 
					
						
							|  |  |  |  |                     continue; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 $validate_fname = 'validate' . $this->getMethodNameFromColumnName($t->name); | 
					
						
							|  |  |  |  |                 // dont re-add it..
 | 
					
						
							|  |  |  |  |                 if (preg_match('/\s+function\s+' . $validate_fname . '\s*\(/i', $input)) { | 
					
						
							|  |  |  |  |                     continue; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 $body .= "\n    function {$validate_fname}()\n    {\n        return false;\n    }\n"; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $foot .= "}\n"; | 
					
						
							|  |  |  |  |         $full = $head . $body . $foot; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (!$input) { | 
					
						
							|  |  |  |  |             return $full; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (!preg_match('/(\n|\r\n)\s*###START_AUTOCODE(\n|\r\n)/s', $input)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             return $full; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (!preg_match('/(\n|\r\n)\s*###END_AUTOCODE(\n|\r\n)/s', $input)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             return $full; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         /* this will only replace extends DB_DataObject by default, | 
					
						
							|  |  |  |  |             unless use set generator_class_rewrite to ANY or a name*/ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $class_rewrite = 'DB_DataObject'; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (empty($options['generator_class_rewrite']) || !($class_rewrite = $options['generator_class_rewrite'])) { | 
					
						
							|  |  |  |  |             $class_rewrite = 'DB_DataObject'; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if ($class_rewrite == 'ANY') { | 
					
						
							|  |  |  |  |             $class_rewrite = '[a-z_]+'; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $input = preg_replace( | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             '/(\n|\r\n)class\s*[a-z0-9_]+\s*extends\s*' . $class_rewrite . '\s*(\n|\r\n)\{(\n|\r\n)/si', | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             "\nclass {$this->classname} extends {$this->_extends} \n{\n", | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $input | 
					
						
							|  |  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $ret = preg_replace( | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             '/(\n|\r\n)\s*###START_AUTOCODE(\n|\r\n).*(\n|\r\n)\s*###END_AUTOCODE(\n|\r\n)/s', | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $body, | 
					
						
							|  |  |  |  |             $input | 
					
						
							|  |  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if (!strlen($ret)) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return (new PEAR)->raiseError( | 
					
						
							|  |  |  |  |                 "PREG_REPLACE failed to replace body, - you probably need to set these in your php.ini\n" . | 
					
						
							|  |  |  |  |                 "pcre.backtrack_limit=1000000\n" . | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 "pcre.recursion_limit=1000000\n", | 
					
						
							|  |  |  |  |                 null, | 
					
						
							|  |  |  |  |                 PEAR_ERROR_DIE | 
					
						
							|  |  |  |  |             ); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         return $ret; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * hook to add extra page-level (in terms of phpDocumentor) DocBlock | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * called once for each class, use it add extra page-level docs | 
					
						
							|  |  |  |  |      * @access public | 
					
						
							|  |  |  |  |      * @return string added to class eg. functions. | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |     public function derivedHookPageLevelDocBlock() | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return ''; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * hook to add extra doc block (in terms of phpDocumentor) to extend string | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * called once for each class, use it add extra comments to extends | 
					
						
							|  |  |  |  |      * string (require_once...) | 
					
						
							|  |  |  |  |      * @access public | 
					
						
							|  |  |  |  |      * @return string added to class eg. functions. | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function derivedHookExtendsDocBlock() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         return ''; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * hook to add extra class level DocBlock (in terms of phpDocumentor) | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * called once for each class, use it add extra comments to class | 
					
						
							|  |  |  |  |      * string (require_once...) | 
					
						
							|  |  |  |  |      * @access public | 
					
						
							|  |  |  |  |      * @return string added to class eg. functions. | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function derivedHookClassDocBlock() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         return ''; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * hook for var lines | 
					
						
							|  |  |  |  |      * called each time a var line is generated, override to add extra var | 
					
						
							|  |  |  |  |      * lines | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param object t containing type,len,flags etc. from tableInfo call | 
					
						
							|  |  |  |  |      * @param int padding number of spaces | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      * @return  string added to class eg. functions. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function derivedHookVar(&$t, $padding) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         // This is so derived generator classes can generate variabels
 | 
					
						
							|  |  |  |  |         // It MUST NOT be changed here!!!
 | 
					
						
							|  |  |  |  |         return ""; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * hook for after var lines ( | 
					
						
							|  |  |  |  |      * called at the end of the output of var line have generated, override to add extra var | 
					
						
							|  |  |  |  |      * lines | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param array cols containing array of objects with type,len,flags etc. from tableInfo call | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      * @return  string added to class eg. functions. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function derivedHookPostVar($t) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         // This is so derived generator classes can generate variabels
 | 
					
						
							|  |  |  |  |         // It MUST NOT be changed here!!!
 | 
					
						
							|  |  |  |  |         return ""; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate getter methods for class definition | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param string $input Existing class contents | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateGetters($input) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $getters = ''; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // only generate if option is set to true
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         if (empty($options['generate_getters'])) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             return ''; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // remove auto-generated code from input to be able to check if the method exists outside of the auto-code
 | 
					
						
							|  |  |  |  |         $input = preg_replace('/(\n|\r\n)\s*###START_AUTOCODE(\n|\r\n).*(\n|\r\n)\s*###END_AUTOCODE(\n|\r\n)/s', '', $input); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $getters .= "\n\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $defs = $this->_definitions[$this->table]; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         // loop through properties and create getter methods
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         foreach ($defs as $t) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             // build mehtod name
 | 
					
						
							|  |  |  |  |             $methodName = 'get' . $this->getMethodNameFromColumnName($t->name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (!strlen(trim($t->name)) || preg_match("/function[\s]+[&]?$methodName\(/i", $input)) { | 
					
						
							|  |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             $getters .= "   /**\n"; | 
					
						
							|  |  |  |  |             $getters .= "    * Getter for \${$t->name}\n"; | 
					
						
							|  |  |  |  |             $getters .= "    *\n"; | 
					
						
							|  |  |  |  |             $getters .= (stristr($t->flags, 'multiple_key')) ? "    * @return   object\n" | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 : "    * @return   {$t->type}\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $getters .= "    * @access   public\n"; | 
					
						
							|  |  |  |  |             $getters .= "    */\n"; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $getters .= (substr(phpversion(), 0, 1) > 4) ? '    public ' | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 : '    '; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $getters .= "function $methodName() {\n"; | 
					
						
							|  |  |  |  |             $getters .= "        return \$this->{$t->name};\n"; | 
					
						
							|  |  |  |  |             $getters .= "    }\n\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         return $getters; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Convert a column name into a method name (usually prefixed by get/set/validateXXXXX) | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access  public | 
					
						
							|  |  |  |  |      * @param $col | 
					
						
							|  |  |  |  |      * @return  string method name; | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public function getMethodNameFromColumnName($col) | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         return ucfirst($col); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * Generate setter methods for class definition | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param string  Existing class contents | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function _generateSetters($input) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         $setters = ''; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // only generate if option is set to true
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         if (empty($options['generate_setters'])) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             return ''; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         // remove auto-generated code from input to be able to check if the method exists outside of the auto-code
 | 
					
						
							|  |  |  |  |         $input = preg_replace('/(\n|\r\n)\s*###START_AUTOCODE(\n|\r\n).*(\n|\r\n)\s*###END_AUTOCODE(\n|\r\n)/s', '', $input); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $setters .= "\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $defs = $this->_definitions[$this->table]; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         // loop through properties and create setter methods
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         foreach ($defs as $t) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             // build mehtod name
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $methodName = 'set' . $this->getMethodNameFromColumnName($t->name); | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             if (!strlen(trim($t->name)) || preg_match("/function[\s]+[&]?$methodName\(/i", $input)) { | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             $setters .= "   /**\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $setters .= "    * Setter for \${$t->name}\n"; | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $setters .= "    *\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $setters .= "    * @param    mixed   input value\n"; | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $setters .= "    * @access   public\n"; | 
					
						
							|  |  |  |  |             $setters .= "    */\n"; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $setters .= (substr(phpversion(), 0, 1) > 4) ? '    public ' | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 : '    '; | 
					
						
							|  |  |  |  |             $setters .= "function $methodName(\$value) {\n"; | 
					
						
							|  |  |  |  |             $setters .= "        \$this->{$t->name} = \$value;\n"; | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |             $setters .= "    }\n\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 12:32:39 +02:00
										 |  |  |  |         return $setters; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate link setter/getter methods for class definition | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * @param string  Existing class contents | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |     public function _generateLinkMethods($input) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $setters = ''; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // only generate if option is set to true
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         // generate_link_methods true::
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (empty($options['generate_link_methods'])) { | 
					
						
							|  |  |  |  |             //echo "skip lm? - not set";
 | 
					
						
							|  |  |  |  |             return ''; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (empty($this->_fkeys)) { | 
					
						
							|  |  |  |  |             // echo "skip lm? - fkyes empty";
 | 
					
						
							|  |  |  |  |             return ''; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (empty($this->_fkeys[$this->table])) { | 
					
						
							|  |  |  |  |             //echo "skip lm? - no fkeys for {$this->table}";
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             return ''; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // remove auto-generated code from input to be able to check if the method exists outside of the auto-code
 | 
					
						
							|  |  |  |  |         $input = preg_replace('/(\n|\r\n)\s*###START_AUTOCODE(\n|\r\n).*(\n|\r\n)\s*###END_AUTOCODE(\n|\r\n)/s', '', $input); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $setters .= "\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $defs = $this->_fkeys[$this->table]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // $fk[$this->table][$tref[1]] = $tref[2] . ":" . $tref[3];
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         // loop through properties and create setter methods
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         foreach ($defs as $k => $info) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             // build mehtod name
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $methodName = is_callable($options['generate_link_methods']) ? | 
					
						
							|  |  |  |  |                 $options['generate_link_methods']($k) : $k; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             if (!strlen(trim($k)) || preg_match("/function[\s]+[&]?$methodName\(/i", $input)) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 continue; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             $setters .= "   /**\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $setters .= "    * Getter / Setter for \${$k}\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $setters .= "    *\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $setters .= "    * @param    mixed   (optional) value to assign\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $setters .= "    * @access   public\n"; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $setters .= "    */\n"; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             $setters .= (substr(phpversion(), 0, 1) > 4) ? '    public ' | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 : '    '; | 
					
						
							|  |  |  |  |             $setters .= "function $methodName() {\n"; | 
					
						
							|  |  |  |  |             $setters .= "        return \$this->link('$k', func_get_args());\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $setters .= "    }\n\n"; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return $setters; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate table Function - used when generator_no_ini is set. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param array  table array. | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateTableFunction($def) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         $defines = explode(',', 'INT,STR,DATE,TIME,BOOL,TXT,BLOB,NOTNULL,MYSQLTIMESTAMP'); | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $ret = "\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    function table()\n" . | 
					
						
							|  |  |  |  |             "    {\n" . | 
					
						
							|  |  |  |  |             "         return array(\n"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         foreach ($def as $k => $v) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             $str = '0'; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             foreach ($defines as $dn) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 if ($v & constant('DB_DATAOBJECT_' . $dn)) { | 
					
						
							|  |  |  |  |                     $str .= ' + DB_DATAOBJECT_' . $dn; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (strlen($str) > 1) { | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 $str = substr($str, 3); // strip the 0 +
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             // hopefully addslashes is good enough here!!!
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $ret .= '             \'' . addslashes($k) . '\' => ' . $str . ",\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         return $ret . "         );\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    }\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate keys Function - used generator_no_ini is set. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param array  keys array. | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateKeysFunction($def) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         $ret = "\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    function keys()\n" . | 
					
						
							|  |  |  |  |             "    {\n" . | 
					
						
							|  |  |  |  |             "         return array("; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         foreach ($def as $k => $type) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // hopefully addslashes is good enough here!!!
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             $ret .= '\'' . addslashes($k) . '\', '; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         $ret = preg_replace('#, $#', '', $ret); | 
					
						
							|  |  |  |  |         return $ret . ");\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    }\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate sequenceKey Function - used generator_no_ini is set. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param array  table and key definition. | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateSequenceKeyFunction($def) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         //print_r($def);
 | 
					
						
							|  |  |  |  |         // DB_DataObject::debugLevel(5);
 | 
					
						
							|  |  |  |  |         global $_DB_DATAOBJECT; | 
					
						
							|  |  |  |  |         // print_r($def);
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $dbtype = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['phptype']; | 
					
						
							|  |  |  |  |         $realkeys = $def['keys']; | 
					
						
							|  |  |  |  |         $keys = array_keys($realkeys); | 
					
						
							|  |  |  |  |         $usekey = isset($keys[0]) ? $keys[0] : false; | 
					
						
							|  |  |  |  |         $table = $def['table']; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $seqname = false; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $ar = array(false, false, false); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         if ($usekey !== false) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             if (!empty($_DB_DATAOBJECT['CONFIG']['sequence_' . $this->__table])) { | 
					
						
							|  |  |  |  |                 $usekey = $_DB_DATAOBJECT['CONFIG']['sequence_' . $this->__table]; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 if (strpos($usekey, ':') !== false) { | 
					
						
							|  |  |  |  |                     list($usekey, $seqname) = explode(':', $usekey); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (in_array($dbtype, array('mysql', 'mysqli', 'mssql', 'ifx')) && | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 ($table[$usekey] & DB_DATAOBJECT_INT) && | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 isset($realkeys[$usekey]) && ($realkeys[$usekey] == 'N') | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             ) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 // use native sequence keys.
 | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                 $ar = array($usekey, true, $seqname); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } else { | 
					
						
							|  |  |  |  |                 // use generated sequence keys..
 | 
					
						
							|  |  |  |  |                 if ($table[$usekey] & DB_DATAOBJECT_INT) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $ar = array($usekey, false, $seqname); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $ret = "\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    function sequenceKey() // keyname, use native, native name\n" . | 
					
						
							|  |  |  |  |             "    {\n" . | 
					
						
							|  |  |  |  |             "         return array("; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($ar as $v) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             switch (gettype($v)) { | 
					
						
							|  |  |  |  |                 case 'boolean': | 
					
						
							|  |  |  |  |                     $ret .= ($v ? 'true' : 'false') . ', '; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case 'string': | 
					
						
							|  |  |  |  |                     $ret .= "'" . $v . "', "; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 default:    // eak
 | 
					
						
							|  |  |  |  |                     $ret .= "null, "; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $ret = preg_replace('#, $#', '', $ret); | 
					
						
							|  |  |  |  |         return $ret . ");\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    }\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |      * Generate defaults Function - used generator_add_defaults or generator_no_ini is set. | 
					
						
							|  |  |  |  |      * Only supports mysql and mysqli ... welcome ideas for more.. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param $table | 
					
						
							|  |  |  |  |      * @param $defs | 
					
						
							|  |  |  |  |      * @return   string | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |     public function _generateDefaultsFunction($table, $defs) | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5]; | 
					
						
							|  |  |  |  |         if (!in_array($__DB->phptype, array('mysql', 'mysqli'))) { | 
					
						
							|  |  |  |  |             return null; // cant handle non-mysql introspection for defaults.
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver']; | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         $method = $db_driver == 'DB' ? 'getAll' : 'queryAll'; | 
					
						
							|  |  |  |  |         $res = $__DB->$method('DESCRIBE ' . $table, DB_FETCHMODE_ASSOC); | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $defaults = array(); | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |         foreach ($res as $ar) { | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             // this is initially very dumb... -> and it may mess up..
 | 
					
						
							|  |  |  |  |             $type = $defs[$ar['Field']]; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             switch (true) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case (is_null($ar['Default'])): | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $defaults[$ar['Field']] = 'null'; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case ($type & DB_DATAOBJECT_DATE): | 
					
						
							|  |  |  |  |                 case ($type & DB_DATAOBJECT_TIME): | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 case ($type & DB_DATAOBJECT_MYSQLTIMESTAMP): // not supported yet..
 | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case ($type & DB_DATAOBJECT_BOOL): | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $defaults[$ar['Field']] = (int)(boolean)$ar['Default']; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:20:20 +01:00
										 |  |  |  |                 case ($type & DB_DATAOBJECT_STR): | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                     $defaults[$ar['Field']] = "'" . addslashes($ar['Default']) . "'"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                 default:    // hopefully eveything else...  - numbers etc.
 | 
					
						
							|  |  |  |  |                     if (!strlen($ar['Default'])) { | 
					
						
							|  |  |  |  |                         continue; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     if (is_numeric($ar['Default'])) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |                         $defaults[$ar['Field']] = $ar['Default']; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |                     } | 
					
						
							|  |  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             //var_dump(array($ar['Field'], $ar['Default'], $defaults[$ar['Field']]));
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (empty($defaults)) { | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             return null; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         $ret = "\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    function defaults() // column default values \n" . | 
					
						
							|  |  |  |  |             "    {\n" . | 
					
						
							|  |  |  |  |             "         return array(\n"; | 
					
						
							|  |  |  |  |         foreach ($defaults as $k => $v) { | 
					
						
							|  |  |  |  |             $ret .= '             \'' . addslashes($k) . '\' => ' . $v . ",\n"; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         return $ret . "         );\n" . | 
					
						
							| 
									
										
										
										
											2019-04-27 18:21:14 +01:00
										 |  |  |  |             "    }\n"; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * hook to add extra methods to all classes | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * called once for each class, use with $this->table and | 
					
						
							|  |  |  |  |      * $this->_definitions[$this->table], to get data out of the current table, | 
					
						
							|  |  |  |  |      * use it to add extra methods to the default classes. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      * @param string $input | 
					
						
							|  |  |  |  |      * @return  string added to class eg. functions. | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function derivedHookFunctions($input = "") | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         // This is so derived generator classes can generate functions
 | 
					
						
							|  |  |  |  |         // It MUST NOT be changed here!!!
 | 
					
						
							|  |  |  |  |         return ""; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * /** | 
					
						
							|  |  |  |  |      * getProxyFull - create a class definition on the fly and instantate it.. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * similar to generated files - but also evals the class definitoin code. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param string database name | 
					
						
							|  |  |  |  |      * @param string  table   name of table to create proxy for. | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @return   object    Instance of class. or PEAR Error | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function getProxyFull($database, $table) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if ($err = $this->fillTableSchema($database, $table)) { | 
					
						
							|  |  |  |  |             return $err; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         $class_prefix = empty($options['class_prefix']) ? '' : $options['class_prefix']; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->_extends = empty($options['extends']) ? $this->_extends : $options['extends']; | 
					
						
							|  |  |  |  |         $this->_extendsFile = !isset($options['extends_location']) ? $this->_extendsFile : $options['extends_location']; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $classname = $this->classname = $this->getClassNameFromTableName($this->table); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $out = $this->_generateClassTable(); | 
					
						
							|  |  |  |  |         //echo $out;
 | 
					
						
							|  |  |  |  |         eval('?>' . $out); | 
					
						
							|  |  |  |  |         return new $classname; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /** | 
					
						
							|  |  |  |  |      * fillTableSchema - set the database schema on the fly | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @param string database name | 
					
						
							|  |  |  |  |      * @param string  table   name of table to create schema info for | 
					
						
							|  |  |  |  |      * | 
					
						
							|  |  |  |  |      * @return none|object|PEAR | 
					
						
							|  |  |  |  |      * @access   public | 
					
						
							|  |  |  |  |      */ | 
					
						
							|  |  |  |  |     public function fillTableSchema($database, $table) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         global $_DB_DATAOBJECT; | 
					
						
							|  |  |  |  |         // a little bit of sanity testing.
 | 
					
						
							|  |  |  |  |         if ((false !== strpos($database, "'")) || (false !== strpos($database, ";"))) { | 
					
						
							|  |  |  |  |             return (new PEAR)->raiseError("Error: Database name contains a quote or semi-colon", null, PEAR_ERROR_DIE); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->_database = $database; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->_connect(); | 
					
						
							|  |  |  |  |         $table = trim($table); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         // a little bit of sanity testing.
 | 
					
						
							|  |  |  |  |         if ((false !== strpos($table, "'")) || (false !== strpos($table, ";"))) { | 
					
						
							|  |  |  |  |             return (new PEAR)->raiseError("Error: Table contains a quote or semi-colon", null, PEAR_ERROR_DIE); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $options = (new PEAR)->getStaticProperty('DB_DataObject', 'options'); | 
					
						
							|  |  |  |  |         $db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver']; | 
					
						
							|  |  |  |  |         $is_MDB2 = ($db_driver != 'DB') ? true : false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (!$is_MDB2) { | 
					
						
							|  |  |  |  |             // try getting a list of schema tables first. (postgres)
 | 
					
						
							|  |  |  |  |             $__DB->expectError(DB_ERROR_UNSUPPORTED); | 
					
						
							|  |  |  |  |             $this->tables = $__DB->getListOf('schema.tables'); | 
					
						
							|  |  |  |  |             $__DB->popExpect(); | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             /** | 
					
						
							|  |  |  |  |              * set portability and some modules to fetch the informations | 
					
						
							|  |  |  |  |              */ | 
					
						
							|  |  |  |  |             $__DB->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE); | 
					
						
							|  |  |  |  |             $__DB->loadModule('Manager'); | 
					
						
							|  |  |  |  |             $__DB->loadModule('Reverse'); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? | 
					
						
							|  |  |  |  |             $__DB->quoteIdentifier($table) : $table; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (!$is_MDB2) { | 
					
						
							|  |  |  |  |             $defs = $__DB->tableInfo($quotedTable); | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             $defs = $__DB->reverse->tableInfo($quotedTable); | 
					
						
							|  |  |  |  |             if ((new PEAR)->isError($defs)) { | 
					
						
							|  |  |  |  |                 return $defs; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             foreach ($defs as $k => $v) { | 
					
						
							|  |  |  |  |                 if (!isset($defs[$k]['length'])) { | 
					
						
							|  |  |  |  |                     continue; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 $defs[$k]['len'] = $defs[$k]['length']; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if ((new PEAR)->isError($defs)) { | 
					
						
							|  |  |  |  |             return $defs; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (@$_DB_DATAOBJECT['CONFIG']['debug'] > 2) { | 
					
						
							|  |  |  |  |             $this->debug("getting def for $database/$table", 'fillTable'); | 
					
						
							|  |  |  |  |             $this->debug(print_r($defs, true), 'defs'); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         // cast all definitions to objects - as we deal with that better.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         foreach ($defs as $def) { | 
					
						
							|  |  |  |  |             if (is_array($def)) { | 
					
						
							|  |  |  |  |                 $this->_definitions[$table][] = (object)$def; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $this->table = trim($table); | 
					
						
							|  |  |  |  |         $ret = $this->_generateDefinitionsTable(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         $_DB_DATAOBJECT['INI'][$database][$table] = $ret['table']; | 
					
						
							|  |  |  |  |         $_DB_DATAOBJECT['INI'][$database][$table . '__keys'] = $ret['keys']; | 
					
						
							|  |  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2008-08-22 09:17:14 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |