Exemplo n.º 1
0
 /**
  * Connect to the database.
  *
  * @return void
  * @access public
  */
 public static function connectToDatabase()
 {
     global $configArray;
     if (!defined('DB_DATAOBJECT_NO_OVERLOAD')) {
         define('DB_DATAOBJECT_NO_OVERLOAD', 0);
     }
     $options =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'options');
     // If we're using PostgreSQL, we need to set up some extra configuration
     // settings so that unique ID sequences are properly registered:
     if (substr($configArray['Database']['database'], 0, 5) == 'pgsql') {
         $tables = array('comments', 'oai_resumption', 'resource', 'resource_tags', 'search', 'session', 'tags', 'user', 'user_list', 'user_resource');
         foreach ($tables as $table) {
             $configArray['Database']['sequence_' . $table] = $table . '_id_seq';
         }
     }
     $options = $configArray['Database'];
     if (substr($configArray['Database']['database'], 0, 5) == 'mysql') {
         // If we're using MySQL, we need to make certain adjustments (ANSI
         // quotes, pipes as concatenation operator) for proper compatibility
         // with code built for other database systems like PostgreSQL or Oracle.
         $obj = new DB_DataObject();
         $conn = $obj->getDatabaseConnection();
         $conn->query("SET @@SESSION.sql_mode='ANSI_QUOTES,PIPES_AS_CONCAT'");
     } else {
         if (substr($configArray['Database']['database'], 0, 4) == 'oci8') {
             // If we are using Oracle, set some portability values:
             $temp_db = new DB_DataObject();
             $db =& $temp_db->getDatabaseConnection();
             $db->setOption('portability', DB_PORTABILITY_NUMROWS | DB_PORTABILITY_NULL_TO_EMPTY);
             // Update the date format to fix issues with Oracle being evil
             $db->query("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'");
         }
     }
 }
Exemplo n.º 2
0
function initDatabase()
{
    global $configArray;
    // Setup Local Database Connection
    define('DB_DATAOBJECT_NO_OVERLOAD', 0);
    $options =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'options');
    $options = $configArray['Database'];
}
Exemplo n.º 3
0
 private function initDatabaseConnection()
 {
     // Setup Local Database Connection
     if (!defined('DB_DATAOBJECT_NO_OVERLOAD')) {
         define('DB_DATAOBJECT_NO_OVERLOAD', 0);
     }
     $options =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'options');
     $options = $this->configArray['Database'];
     $this->logTime("Connect to databse");
     require_once ROOT_DIR . '/Drivers/marmot_inc/Library.php';
 }
Exemplo n.º 4
0
 /**
  * Save the object to the database (and optionally solr) based on the structure of the object
  * Takes care of determining whether or not the object is new or not.
  *
  * @param $dataObject
  * @param $form
  */
 static function saveObject($structure, $dataType)
 {
     global $logger;
     //Check to see if we have a new object or an exiting object to update
     $object = new $dataType();
     DataObjectUtil::updateFromUI($object, $structure);
     $primaryKeySet = false;
     foreach ($structure as $property) {
         if (isset($property['primaryKey']) && $property['primaryKey'] == true) {
             if (isset($object->{$property}['property']) && !is_null($object->{$property}['property']) && strlen($object->{$property}['property']) > 0) {
                 $object = new $dataType();
                 $object->{$property}['property'] = $object->{$property}['property'];
                 if ($object->find(true)) {
                     $logger->log("Loaded existing object from database", PEAR_LOG_DEBUG);
                 } else {
                     $logger->log("Could not find existing object in database", PEAR_LOG_ERR);
                 }
                 //Reload from UI
                 DataObjectUtil::updateFromUI($object, $structure);
                 $primaryKeySet = true;
                 break;
             }
         }
     }
     $validationResults = DataObjectUtil::validateObject($structure, $object);
     $validationResults['object'] = $object;
     if ($validationResults['validatedOk']) {
         //Check to see if we need to insert or update the object.
         //We can tell which to do based on whether or not the primary key is set
         if ($primaryKeySet) {
             $result = $object->update();
             $validationResults['saveOk'] = $result == 1;
         } else {
             $result = $object->insert();
             $validationResults['saveOk'] = $result;
         }
         if (!$validationResults['saveOk']) {
             //TODO: Display the PEAR error (in certain circumstances only?)
             $error =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'lastError');
             if (isset($error)) {
                 $validationResults['errors'][] = 'Save failed ' . $error->getMessage();
             } else {
                 $validationResults['errors'][] = 'Save failed';
             }
         }
     }
     return $validationResults;
 }