예제 #1
0
 public function HookInstall()
 {
     $generator = new DB_DataObject2_Generator();
     $generator->start();
     return;
 }
예제 #2
0
 /**
  * Autoload or manually load the table definitions
  *
  *
  * usage :
  * DB_DataObject2::databaseStructure(  'databasename',
  *                                    parse_ini_file('mydb.ini',true), 
  *                                    parse_ini_file('mydb.link.ini',true)); 
  *
  * obviously you dont have to use ini files.. (just return array similar to ini files..)
  *  
  * It should append to the table structure array 
  *
  *     
  * @param optional string  name of database to assign / read
  * @param optional array   structure of database, and keys
  * @param optional array  table links
  *
  * @access public
  * @return true or PEAR:error on wrong paramenters.. or false if no file exists..
  *              or the array(tablename => array(column_name=>type)) if called with 1 argument.. (databasename)
  */
 function databaseStructure()
 {
     if (!$this->__table) {
         return true;
     }
     // Assignment code
     if ($args = func_get_args()) {
         if (count($args) == 1) {
             // this returns all the tables and their structure..
             if (!empty(DB_DataObject2::$CONFIG['debug'])) {
                 $this->debug("Loading Generator as databaseStructure called with args", 1);
             }
             $x = new DB_DataObject();
             $x->_database = $args[0];
             $this->_connect();
             $DB =& DB_DataObject2::$CONNECTIONS[$this->_database_dsn_md5];
             $tables = $DB->getListOf('tables');
             class_exists('DB_DataObject2_Generator', false) ? '' : (require_once DATAOBJECT2_PATH . '/Generator.php');
             foreach ($tables as $table) {
                 $y = new DB_DataObject2_Generator();
                 $y->fillTableSchema($x->_database, $table);
             }
             return DB_DataObject2::$INI[$x->_database];
         } else {
             DB_DataObject2::$INI[$args[0]] = isset(DB_DataObject2::$INI[$args[0]]) ? DB_DataObject2::$INI[$args[0]] + $args[1] : $args[1];
             if (isset($args[1])) {
                 DB_DataObject2::$LINKS[$args[0]] = isset(DB_DataObject2::$LINKS[$args[0]]) ? DB_DataObject2::$LINKS[$args[0]] + $args[2] : $args[2];
             }
             return true;
         }
     }
     if (!$this->_database || !$this->_database_name) {
         $this->_connect();
     }
     // loaded already?
     if (!empty(DB_DataObject2::$INI[$this->_database])) {
         // database loaded - but this is table is not available..
         if (empty(DB_DataObject2::$INI[$this->_database][$this->__table]) && !empty(DB_DataObject2::$CONFIG['proxy'])) {
             if (!empty(DB_DataObject2::$CONFIG['debug'])) {
                 $this->debug("Loading Generator to fetch Schema", 1);
             }
             class_exists('DB_DataObject2_Generator', false) ? '' : (require_once DATAOBJECT2_PATH . '/Generator.php');
             $x = new DB_DataObject2_Generator();
             $x->fillTableSchema($this->_database, $this->__table);
         }
         return true;
     }
     if (empty(DB_DataObject2::$CONFIG)) {
         DB_DataObject2::_loadConfig();
     }
     // if you supply this with arguments, then it will take those
     // as the database and links array...
     $schemas = isset(DB_DataObject2::$CONFIG['schema_location']) ? array(DB_DataObject2::$CONFIG['schema_location'] . "/" . $this->_database . ".ini") : array();
     if (isset(DB_DataObject2::$CONFIG["ini_{$this->_database}"])) {
         $schemas = is_array(DB_DataObject2::$CONFIG["ini_{$this->_database}"]) ? DB_DataObject2::$CONFIG["ini_{$this->_database}"] : explode(PATH_SEPARATOR, DB_DataObject2::$CONFIG["ini_{$this->_database}"]);
     } else {
         if (isset(DB_DataObject2::$CONFIG['schema_location'])) {
             if (is_array(DB_DataObject2::$CONFIG['schema_location'])) {
                 $schema_locations = DB_DataObject2::$CONFIG['schema_location'];
             } else {
                 $schema_locations = array(DB_DataObject2::$CONFIG['schema_location']);
             }
         } else {
             $schema_locations = array();
         }
         $schemas = array();
         foreach ($schema_locations as $schema_location) {
             $schemas[] = $schema_location . DIRECTORY_SEPARATOR . $this->_database . ".ini";
         }
     }
     foreach ($schemas as $ini) {
         if (file_exists($ini) && is_file($ini)) {
             /* not sure why $links = ... here  - TODO check if that works */
             if (!isset(DB_DataObject2::$INI[$this->_database])) {
                 DB_DataObject2::$INI[$this->_database] = array();
             }
             $new = parse_ini_file($ini, true);
             DB_DataObject2::$INI[$this->_database] = array_merge_recursive_unique(DB_DataObject2::$INI[$this->_database], $new);
             if (!empty(DB_DataObject2::$CONFIG['debug'])) {
                 $this->debug("Loaded ini file: {$ini}", "databaseStructure", 1);
             }
         } else {
             if (!empty(DB_DataObject2::$CONFIG['debug'])) {
                 $this->debug("Missing ini file: {$ini}", "databaseStructure", 1);
             }
         }
     }
     // now have we loaded the structure..
     if (!empty(DB_DataObject2::$INI[$this->_database][$this->__table])) {
         return true;
     }
     // - if not try building it..
     if (!empty(DB_DataObject2::$CONFIG['proxy'])) {
         class_exists('DB_DataObject2_Generator', false) ? '' : (require_once DATAOBJECT2_PATH . '/Generator.php');
         $x = new DB_DataObject2_Generator();
         $x->fillTableSchema($this->_database, $this->__table);
         // should this fail!!!???
         return true;
     }
     $this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n" . "in links file data: " . print_r(DB_DataObject2::$INI, true), "databaseStructure", 5);
     // we have to die here!! - it causes chaos if we dont (including looping forever!)
     throw new Exception("Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS);
 }
예제 #3
0
// $Id: createTables.php,v 1.24 2006/01/13 01:27:55 alan_k Exp $
//
require_once 'dataobject2/DataObject2.php';
require_once DATAOBJECT2_PATH . 'DataObject2/Generator.php';
if (!ini_get('register_argc_argv')) {
    echo "\nERROR: You must turn register_argc_argv On in you php.ini file for this to work\neg.\n\nregister_argc_argv = On\n\n";
    exit;
}
if (!@$_SERVER['argv'][1]) {
    echo "\nERROR: createTable.php usage:\n\nC:\\php\\pear\\DB\\DataObjects\\createTable.php example.ini\nC:\\php\\pear\\DB\\DataObjects\\createTable.php php config.php\n";
    exit;
}
if ($_SERVER['argv'][1] == 'php') {
    require_once $_SERVER['argv'][2];
} else {
    $config = parse_ini_file($_SERVER['argv'][1], true);
    foreach ($config as $class => $values) {
        $options =& PEAR::getStaticProperty($class, 'options');
        $options = $values;
    }
}
$options =& PEAR::getStaticProperty('DB_DataObject2', 'options');
if (empty($options)) {
    echo "\nERROR: could not read config\n\n";
    exit;
}
set_time_limit(0);
// use debug level from file if set..
DB_DataObject2::debugLevel(isset($options['debug']) ? $options['debug'] : 1);
$generator = new DB_DataObject2_Generator();
$generator->start();