/** * Store the effective and expiration Dates. getEffectiveDate or getExpirationDate * should be called first to set the datesInDB flag. * * @return void * @access public * @since 8/10/04 */ function _storeDates() { $dbHandler = Services::getService("DatabaseManager"); $id = $this->_node->getId(); // If we have stored dates for this asset set them if ($this->_datesInDB) { $query = new UpdateQuery(); $query->addWhereEqual("asset_id", $id->getIdString()); } else { $query = new InsertQuery(); $query->addValue("asset_id", $id->getIdString()); $query->addRawValue("create_timestamp", "NOW()"); // Add the creator $agentId = $this->_getCurrentAgent(); $query->addValue("creator", $agentId->getIdString()); } if (is_object($this->_effectiveDate)) { $query->addValue("effective_date", $dbHandler->toDBDate($this->_effectiveDate, $this->_dbIndex)); } else { $query->addRawValue("effective_date", "NULL"); } if (is_object($this->_expirationDate)) { $query->addValue("expiration_date", $dbHandler->toDBDate($this->_expirationDate, $this->_dbIndex)); } else { $query->addRawValue("expiration_date", "NULL"); } $query->addRawValue("modify_timestamp", "NOW()"); $query->setTable("dr_asset_info"); $result = $dbHandler->query($query, $this->_dbIndex); }
/** * Record an entry for the slot in the local database * * @return void * @access private * @since 8/14/07 */ private function recordInDB() { if (!$this->isInDB) { $dbc = Services::getService('DBHandler'); try { // Add a row to the slot table $query = new InsertQuery(); $query->setTable('segue_slot'); $query->addValue('shortname', $this->getShortname()); if ($this->siteId) { $query->addValue('site_id', $this->siteId->getIdString()); } $query->addValue('type', $this->getType()); $query->addValue('location_category', $this->getLocationCategory()); if ($this->mediaQuota == self::$defaultMediaQuota) { $query->addRawValue('media_quota', 'null'); } else { $query->addValue('media_quota', $this->mediaQuota); } $dbc->query($query, IMPORTER_CONNECTION); } catch (DuplicateKeyDatabaseException $e) { // Update row to the slot table $query = new UpdateQuery(); $query->setTable('segue_slot'); $query->addWhereEqual('shortname', $this->getShortname()); if ($this->siteId) { $query->addValue('site_id', $this->siteId->getIdString()); } $query->addValue('type', $this->getType()); $query->addValue('location_category', $this->getLocationCategory()); if ($this->mediaQuota == self::$defaultMediaQuota) { $query->addRawValue('media_quota', 'null'); } else { $query->addValue('media_quota', $this->mediaQuota); } $dbc->query($query, IMPORTER_CONNECTION); } // Add existing owners to the slot_owner table // Adam 2007-08-16: Not sure if we actually need to do this... if (count($this->getOwners())) { $query = new InsertQuery(); $query->setTable('segue_slot_owner'); foreach ($this->getOwners() as $ownerId) { $query->addValue('shortname', $this->getShortname()); $query->addValue('owner_id', $ownerId->getIdString()); try { $dbc->query($query, IMPORTER_CONNECTION); } catch (DuplicateKeyDatabaseException $e) { // If already there, just skip. } } } $this->isInDB = true; } }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { if (!is_null($value)) { ArgumentValidator::validate($value, StringValidatorRule::getRule()); } // Store the name in the object in case its asked for again. if (is_null($value)) { $this->_name = ''; } else { $this->_name = $value; } // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // Check to see if the name is in the database $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); if (is_null($value)) { $query->addRawValue("filename", "NULL"); } else { $query->addValue("filename", $this->_name); } $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->addValue("id", $this->_recordId->getIdString()); if (is_null($value)) { $query->addRawValue("filename", "NULL"); } else { $query->addValue("filename", $this->_name); } } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Record a visit in the database * * @param string $slotname * @return void * @access protected * @since 9/22/08 */ protected function _recordVisit($slotname) { $dbc = Services::getService('DatabaseManager'); // First try running an update query, since most will be updates $query = new UpdateQuery(); $query->setTable('segue_accesslog'); $query->addRawValue('tstamp', 'NOW()'); $query->addWhereEqual('agent_id', $this->_getCurrentAgentId()); $query->addWhereEqual('fk_slotname', $slotname); $result = $dbc->query($query, IMPORTER_CONNECTION); // If no rows were updated, insert a new one for this user/slot if (!$result->getNumberOfRows()) { $query = new InsertQuery(); $query->setTable('segue_accesslog'); $query->addRawValue('tstamp', 'NOW()'); $query->addValue('agent_id', $this->_getCurrentAgentId()); $query->addValue('fk_slotname', $slotname); try { $dbc->query($query, IMPORTER_CONNECTION); } catch (DuplicateKeyDatabaseException $e) { // multiple requests may colide, just ignore. } } }
/** * Create an implicit AZ at a nodeId for an explicit AZ. * * @param object Authorization $explicitAZ * @param object Id $nodeId * @return void * @access protected * @since 4/21/08 */ protected function createImplicitAZ(Authorization $explicitAZ, Id $nodeId) { if (isset($this->harmoni_db)) { if (!isset($this->createImplicitAZ_stmt)) { $query = $this->harmoni_db->insert(); $query->setTable("az2_implicit_az"); $query->addRawValue("fk_explicit_az", "?"); $query->addRawValue("fk_agent", "?"); $query->addRawValue("fk_function", "?"); $query->addRawValue("fk_qualifier", "?"); $query->addRawValue("effective_date", "?"); $query->addRawValue("expiration_date", "?"); $this->createImplicitAZ_stmt = $query->prepare(); } $this->createImplicitAZ_stmt->bindValue(1, $explicitAZ->getIdString()); $this->createImplicitAZ_stmt->bindValue(2, $explicitAZ->getAgentId()->getIdString()); $this->createImplicitAZ_stmt->bindValue(3, $explicitAZ->getFunction()->getId()->getIdString()); $this->createImplicitAZ_stmt->bindValue(4, $nodeId->getIdString()); $effectiveDate = $explicitAZ->getEffectiveDate(); if (is_null($effectiveDate)) { $this->createImplicitAZ_stmt->bindValue(5, null); } else { $this->createImplicitAZ_stmt->bindValue(5, $effectiveDate->asString()); } $expirationDate = $explicitAZ->getExpirationDate(); if (is_null($expirationDate)) { $this->createImplicitAZ_stmt->bindValue(6, null); } else { $this->createImplicitAZ_stmt->bindValue(6, $expirationDate->asString()); } try { $this->createImplicitAZ_stmt->execute(); } catch (Exception $e) { printpre($e->getMessage()); printpre("fk_explicit_az => " . $explicitAZ->getIdString() . "\nfk_agent => " . $explicitAZ->getAgentId()->getIdString() . "\nfk_function => " . $explicitAZ->getFunction()->getId()->getIdString() . "\nfk_qualifier => " . $explicitAZ->getAgentId()->getIdString()); printpre(__LINE__); exit; } } else { // now insert into database $dbHandler = Services::getService("DatabaseManager"); $query = new InsertQuery(); $query->setTable("az2_implicit_az"); $query->addValue("fk_explicit_az", $explicitAZ->getIdString()); $query->addValue("fk_agent", $explicitAZ->getAgentId()->getIdString()); $query->addValue("fk_function", $explicitAZ->getFunction()->getId()->getIdString()); $query->addValue("fk_qualifier", $nodeId->getIdString()); $effectiveDate = $explicitAZ->getEffectiveDate(); if (is_null($effectiveDate)) { $query->addRawValue("effective_date", "NULL"); } else { $query->addValue("effective_date", $effectiveDate->asString()); } $expirationDate = $explicitAZ->getExpirationDate(); if (is_null($expirationDate)) { $query->addRawValue("expiration_date", "NULL"); } else { $query->addValue("expiration_date", $expirationDate->asString()); } $dbHandler->query($query, $this->_dbIndex); } }