/**
  * Add a new Id to the set.
  * @param object Id $id The Id to add.
  * @access public
  * @return void
  */
 function addItem($id)
 {
     parent::addItem($id);
     $position = $this->getPosition($id);
     // Add the item to the database
     $query = new InsertQuery();
     $query->setTable("sets");
     $columns = array("id", "item_id", "item_order");
     $values = array("'" . addslashes($this->_setId->getIdString()) . "'", "'" . addslashes($id->getIdString()) . "'", "'" . $position . "'");
     $query->setColumns($columns);
     $query->setValues($values);
     $dbHandler = Services::getService("DatabaseManager");
     $dbHandler->query($query, $this->_dbIndex);
 }
 /**
  * Inserts a new row into the Database with the data contained in the object.
  * @param integer $dbID The {@link DBHandler} database ID to query.
  * @access public
  * @return integer Returns the new ID of the data stored.
  */
 function insert($dbID)
 {
     $idManager = Services::getService("Id");
     $newID = $idManager->createId();
     $query = new InsertQuery();
     $query->setTable($this->_table);
     $query->setColumns(array("id", "data"));
     $query->addRowOfValues(array("'" . addslashes($newID->getIdString()) . "'", "'" . addslashes($this->asString()) . "'"));
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $dbID);
     if (!$result || $result->getNumberOfRows() != 1) {
         throwError(new UnknownDBError("StorableString"));
         return false;
     }
     return $newID->getIdString();
 }
示例#3
0
 /**
  * Add this tag to an Item
  * 
  * @param object TaggedItem $item
  * @return object The item
  * @access public
  * @since 11/6/06
  */
 function tagItem($item)
 {
     // Make sure the item is not already tagged
     if ($this->isItemTagged($item)) {
         return $item;
     }
     // Make sure the tag has a non-zero length
     if (!$this->getValue()) {
         return $item;
     }
     $query = new InsertQuery();
     $query->setTable('tag');
     $query->setColumns(array('value', 'user_id', 'fk_item'));
     $query->setValues(array("'" . addslashes($this->getValue()) . "'", "'" . addslashes($this->getCurrentUserIdString()) . "'", "'" . addslashes($item->getDatabaseId()) . "'"));
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     return $item;
 }
示例#4
0
 /**
  * Takes a {@link DMRecord} and an optional date and creates a {@link RecordTag} in the database based
  * on the current active versions of values within the {@link DMRecord}.
  * @param ref object $record The {@link DMRecord} to be tagged.
  * @param optional object $date An optional {@link DateAndTime} object to attach to the tag instead of the current date/time.
  * @return int The new tag's ID in the database.
  * @access public
  */
 function tagRecord($record, $date = null)
 {
     // if the dataset is not versionControlled, there's no point in tagging
     if (!$record->isVersionControlled()) {
         return null;
     }
     $id = $record->getID();
     if (!$date) {
         $date = DateAndTime::now();
     }
     // spider through the record and get the IDs of the active versions.
     $ids = array();
     $schema = $record->getSchema();
     foreach ($schema->getAllIDs() as $id) {
         $values = $record->getRecordFieldValues($id);
         foreach (array_keys($values) as $key) {
             if ($values[$key]->hasActiveValue()) {
                 $actVer = $values[$key]->getActiveVersion();
                 $ids[] = $actVer->getID();
             }
         }
     }
     // now let's dump it all to the DB
     $query = new InsertQuery();
     $query->setTable("dm_tag");
     $query->setColumns(array("id", "fk_record", "date"));
     $idManager = Services::getService("Id");
     $dbHandler = Services::getService("DBHandler");
     $newID = $idManager->createId();
     $query->addRowOfValues(array($newID->getIdString(), $id, $dbHandler->toDBDate($date, DATAMANAGER_DBID)));
     $query2 = new InsertQuery();
     $query2->setTable("dm_tag_map");
     $query2->setColumns(array("fk_tag", "fk_record_field"));
     foreach ($ids as $id) {
         $query2->addRowOfValues(array("'" . addslashes($newID->getIdString()) . "'", $id));
     }
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     $result2 = $dbHandler->query($query2, DATAMANAGER_DBID);
     if (!$result || !$result2) {
         throwError(new UnknownDBError("RecordTagManager"));
     }
     // we're done.
     return $newID->getIdString();
 }
 /**
  * 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)
 {
     ArgumentValidator::validate($value, StringValidatorRule::getRule());
     // Store the size in the object in case its asked for again.
     try {
         $size = ByteSize::fromString($value);
     } catch (InvalidArgumentException $e) {
         $size = ByteSize::withValue(0);
     }
     $this->_size = $size->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");
         $query->setColumns(array("size"));
         $query->setValues(array("'" . addslashes($this->_size) . "'"));
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("id", "size"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
示例#6
0
 /**
  * Answer the mime type key
  * 
  * @param string $mimeType
  * @return integer
  * @access public
  * @since 2/13/06
  */
 function getMimeKey()
 {
     // If we have a key, make sure it exists.
     if ($this->_mimeType && $this->_mimeType != "NULL") {
         $dbc = Services::getService('DatabaseManager');
         // Check to see if the type is in the database
         $query = new SelectQuery();
         $query->addTable("dr_mime_type");
         $query->addColumn("id");
         $query->addWhere("type = '" . $this->_mimeType . "'");
         $result = $dbc->query($query, $this->getDBIndex());
         // If it doesn't exist, insert it.
         if (!$result->getNumberOfRows()) {
             $query = new InsertQuery();
             $query->setTable("dr_mime_type");
             $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq");
             $query->setColumns(array("type"));
             $query->setValues(array("'" . addslashes($this->_mimeType) . "'"));
             $result2 = $dbc->query($query, $this->getDBIndex());
             $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'";
         } else {
             $mimeId = "'" . $result->field("id") . "'";
         }
         $result->free();
     } else {
         $mimeId = "NULL";
     }
     return $mimeId;
 }
示例#7
0
 /**
  * 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, NonzeroLengthStringValidatorRule::getRule());
     }
     // Store the name in the object in case its asked for again.
     $this->_type = $value;
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // If we have a key, make sure it exists.
     if ($this->_type && $this->_type != "NULL") {
         // Check to see if the type is in the database
         $query = new SelectQuery();
         $query->addTable("dr_mime_type");
         $query->addColumn("id");
         $query->addWhere("type = '" . $this->_type . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // If it doesn't exist, insert it.
         if (!$result->getNumberOfRows()) {
             $query = new InsertQuery();
             $query->setTable("dr_mime_type");
             $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq");
             $query->setColumns(array("type"));
             $query->setValues(array("'" . addslashes($this->_type) . "'"));
             $result2 = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
             $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'";
         } else {
             $mimeId = "'" . $result->field("id") . "'";
         }
         $result->free();
     } else {
         $mimeId = "NULL";
     }
     // add its id to the file.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->setColumns(array("fk_mime_type"));
     $query->setValues(array($mimeId));
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
示例#8
0
 /**
  * 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.
     $this->_value = $value;
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the row if we are setting the value to null
     if (is_null($value)) {
         $query = new DeleteQuery();
         $query->setTable("dr_file_data");
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         $this->_asset->updateModificationDate();
         return;
     }
     // Check to see if the name is in the database
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_url");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("fk_file = '" . $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_url");
         $query->setColumns(array("url"));
         $query->setValues(array("'" . addslashes($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_url");
         $query->setColumns(array("fk_file", "url"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($value) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
示例#9
0
 /**
  * Add the specified RecordStructure and all the related Records from the
  * specified asset.  The current and future content of the specified
  * Record is synchronized automatically.
  * 
  * @param object Id $assetId
  * @param object Id $recordStructureId
  * 
  * @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}, {@link
  *         org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID},
  *         {@link
  *         org.osid.repository.RepositoryException#ALREADY_INHERITING_STRUCTURE
  *         ALREADY_INHERITING_STRUCTURE}
  * 
  * @access public
  */
 function inheritRecordStructure(Id $assetId, Id $recordStructureId)
 {
     // If this is a schema that is hard coded into our implementation, create
     // a record for that schema.
     if (in_array($recordStructureId->getIdString(), array_keys($this->_repository->_builtInTypes))) {
         // Create an Id for the record;
         $idManager = Services::getService("Id");
         $dbHandler = Services::getService("DatabaseManager");
         // get the record ids that we want to inherit
         $query = new SelectQuery();
         $query->addTable("dr_asset_record");
         $query->addColumn("fk_record");
         $query->addWhere("fk_asset = '" . $assetId->getIdString() . "'");
         $query->addWhere("structure_id = '" . $recordStructureId->getIdString() . "'", _AND);
         $result = $dbHandler->query($query, $this->_dbIndex);
         // store a relation to the record
         $dbHandler = Services::getService("DatabaseManager");
         $query = new InsertQuery();
         $query->setTable("dr_asset_record");
         $query->setColumns(array("fk_asset", "fk_record", "structure_id"));
         $myId = $this->getId();
         while ($result->hasMoreRows()) {
             $query->addRowOfValues(array("'" . $myId->getIdString() . "'", "'" . $result->field("fk_record") . "'", "'" . $recordStructureId->getIdString() . "'"));
             $dbHandler->query($query, $this->_dbIndex);
             $result->advanceRow();
         }
         $result->free();
     } else {
         // Get our managers:
         $recordMgr = Services::getService("RecordManager");
         $idMgr = Services::getService("Id");
         // Get the DataSetGroup for this Asset
         $myId = $this->_node->getId();
         $mySet = $recordMgr->fetchRecordSet($myId->getIdString());
         // Get the DataSetGroup for the source Asset
         $otherSet = $recordMgr->fetchRecordSet($assetId->getIdString());
         $otherSet->loadRecords(RECORD_FULL);
         $records = $otherSet->getRecords();
         // Add all of DataSets (Records) of the specified RecordStructure and Asset
         // to our RecordSet.
         foreach (array_keys($records) as $key) {
             // Get the ID of the current DataSet's TypeDefinition
             $schema = $records[$key]->getSchema();
             $schemaId = $idMgr->getId($schema->getID());
             // If the current DataSet's DataSetTypeDefinition's ID is the same as
             // the RecordStructure ID that we are looking for, add that dataSet to our
             // DataSetGroup.
             if ($recordStructureId->isEqual($schemaId)) {
                 $mySet->add($records[$key]);
             }
         }
         // Save our DataSetGroup
         $mySet->commit(TRUE);
     }
     $this->updateModificationDate();
 }
 /**
  * A public function for getting a type id (and ensuring that it exists
  * in the database). One might consider implementing a Type manager for 
  * stuff like this that has no proper home.
  * 
  * @param object Type $type
  *
  * @return integer
  *
  * @access public
  *
  * @since 11/18/04
  */
 function getTypeId($type)
 {
     $dbc = Services::getService("DBHandler");
     // Check to see if the type already exists in the DB
     $query = new SelectQuery();
     $query->addColumn("type_id");
     $query->addTable("type");
     $query->addWhere("type_domain='" . addslashes($type->getDomain()) . "'");
     $query->addWhere("type_authority='" . addslashes($type->getAuthority()) . "'", _AND);
     $query->addWhere("type_keyword='" . addslashes($type->getKeyword()) . "'", _AND);
     $result = $dbc->query($query, $this->_dbIndex);
     // If we have a type id already, use that
     if ($result->getNumberOfRows()) {
         $typeId = $result->field("type_id");
         $result->free();
     } else {
         $result->free();
         $query = new InsertQuery();
         $query->setTable("type");
         $query->setAutoIncrementColumn("type_id", "type_type_id_seq");
         $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description"));
         $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
         $result = $dbc->query($query, $this->_dbIndex);
         $typeId = $result->getLastAutoIncrementValue();
     }
     return $typeId;
 }
示例#11
0
 /**
  * Build the ancestory rows for a given node
  * 
  * @param object Id $id
  * @return void
  * @access public
  * @since 11/4/05
  */
 function rebuildNodeAncestory(Id $id)
 {
     if (isset($this->harmoni_db)) {
         return $this->rebuildNodeAncestory_Harmoni_Db($id);
     }
     // 		print "<hr/><hr/>";
     // 		print "<strong>"; printpre($id); print "</strong>";
     $idString = $id->getIdString();
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the old ancestory rows
     $this->clearNodeAncestory($idString);
     // Make sure we have traversed the authoratative parent/child hierarchy
     // To determine the new ancestory of the nodes
     if (!$this->_isCachedUp($idString, -1)) {
         $this->_traverseUp($idString, -1);
     }
     // now that all nodes are cached, add their ids to the ancestor table for
     // easy future searching.
     $query = new InsertQuery();
     $query->setTable("az2_node_ancestry");
     $query->setColumns(array("fk_hierarchy", "fk_node", "fk_ancestor", "level", "fk_ancestors_child"));
     $treeNode = $this->_tree->getNode($idString);
     $treeNodes = $this->_tree->traverse($treeNode, false, -1);
     if (count($treeNodes) > 1) {
         foreach (array_keys($treeNodes) as $i => $key) {
             $node = $this->_cache[$key][0];
             // If the node was deleted, but the cache still has a key for it,
             // continue.
             if (!is_object($node)) {
                 continue;
             }
             $nodeId = $node->getId();
             // 				printpre($nodeId->getIdString());
             if (!$nodeId->isEqual($id)) {
                 foreach ($treeNodes[$key]['children'] as $ancestorChildId) {
                     $query->addRowOfValues(array("'" . addslashes($this->_hierarchyId) . "'", "'" . addslashes($idString) . "'", "'" . addslashes($nodeId->getIdString()) . "'", "'" . addslashes($treeNodes[$key][1]) . "'", "'" . addslashes($ancestorChildId) . "'"));
                 }
             } else {
                 $query->addRowOfValues(array("'" . addslashes($this->_hierarchyId) . "'", "'" . addslashes($idString) . "'", "NULL", "'0'", "NULL"));
             }
         }
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
         // 		$queryResult->free();
     }
 }
示例#12
0
 /**
  * Installs a plugin
  * 
  * @param object HarmoniType $type gives us the location of plugin to be 
  * installed
  * @access public
  * @since 3/6/06
  */
 function installPlugin($type)
 {
     // @todo deal with new plugin readiness structure, and database tables
     $authZ = Services::getService("AuthZ");
     //		if ($authZ->isUserAuthorized("edu.middlebury.authorization.add_children", ??))	{
     $dr = Services::getService("Repository");
     $dm = Services::getService("DataTypeManager");
     $db = Services::getService("DBHandler");
     $id = Services::getService("Id");
     // a few things we need
     $site_rep = $dr->getRepository($id->getId("edu.middlebury.segue.sites_repository"));
     $pluginDir = $this->getConfiguration('plugin_dir');
     $types = $dm->getRegisteredTypes();
     // for partstructures
     // use the plugin type to get through the filesystem
     $domain = $type->getDomain();
     $authority = $type->getAuthority();
     $keyword = $type->getKeyword();
     $description = "The type for a {$domain} {$authority} {$keyword} plugin.";
     // write the type to the database
     $query = new InsertQuery();
     $query->setTable('plugin_type');
     $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description", "type_enabled"));
     $query->addRowOfValues(array("'" . addslashes($domain) . "'", "'" . addslashes($authority) . "'", "'" . addslashes($keyword) . "'", "'" . addslashes($description) . "'", '0'));
     $db->query($query, IMPORTER_CONNECTION);
     // grab the xml file
     $xmlFile = $pluginDir . "/" . $domain . "/" . $authority . "/" . $keyword . "/" . $authority . $keyword . "Plugin.xml";
     // if there is no file then the plugin has no data structures
     if (is_file($xmlFile)) {
         $document = new DOMDocument();
         $document->loadXML($xmlFile);
         $recordStructures = $document->documentElement->childNodes;
         // first create the recordstructure(s)
         foreach ($recordStructures as $rs) {
             if ($rs->hasAttribute("name")) {
                 $rsName = $rs->getAttribute("name");
                 $plugStruct = $site_rep->createRecordStructure($rsName, "This is the {$rsName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", "", "");
                 $pSId = $plugStruct->getId();
                 $partStructures = $rs->childNodes;
                 // now create the partstructure(s)
                 foreach ($partStructures as $ps) {
                     if ($ps->hasAttribute("name") && $ps->hasAttribute("type")) {
                         $psName = $ps->getAttribute("name");
                         $psType = $ps->getAttribute("type");
                         if (in_array($psType, $types)) {
                             $plugStruct->createPartStructure($psName, "This is the {$psName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", new Type("Repository", "edu.middlebury.segue", $psType), false, true, false);
                         }
                     }
                 }
                 // write to the DB the plugin and its structures
                 $typeId = null;
                 $query2 = new SelectQuery();
                 $query2->addTable("plugin_type");
                 $query2->addColumn("*");
                 $query2->addWhere("type_domain = '" . addslashes($domain) . "'");
                 $query2->addWhere("type_authority = '" . addslashes($authority) . "'");
                 $query2->addWhere("type_keyword = '" . addslashes($keyword) . "'");
                 $results = $db->query($query2, IMPORTER_CONNECTION);
                 if ($results->getNumberOfRows() == 1) {
                     $result = $results->next();
                     $typeId = $result['type_id'];
                     $results->free();
                     $query3 = new InsertQuery();
                     $query3->setTable("plugin_manager");
                     $query3->setColumns(array("fk_plugin_type", "fk_schema"));
                     $query3->addRowOfValues(array("'" . addslashes($typeId) . "'", "'" . addslashes($pSId->getIdString()) . "'"));
                     $db->query($query3, IMPORTER_CONNECTION);
                 } else {
                     $results->free();
                     throwError(new Error("PluginType not found", "Plugins", false));
                 }
             }
         }
     }
     if (!in_array($type->asString(), array_keys($this->getInstalledPlugins()))) {
         $this->addPluginToArray($type);
     }
     //	}
 }
示例#13
0
 /**
  * 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_array($value)) {
         $this->_dimensions = $value;
         $dbHandler = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addTable($this->_table);
         $query->addColumn("COUNT(*)", "count");
         $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         if ($result->field("count") > 0) {
             $query = new UpdateQuery();
             $query->setTable($this->_table);
             $query->setColumns(array($this->_widthColumn, $this->_heightColumn));
             $query->setValues(array("'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'"));
             $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'");
         } else {
             $query = new InsertQuery();
             $query->setTable($this->_table);
             $query->setColumns(array($this->_idColumn, $this->_widthColumn, $this->_heightColumn));
             $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'"));
         }
         $result->free();
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // This gets done during thumbnail generation, so don't change our
         // asset's modification date.
         // 			$this->_asset->updateModificationDate();
     }
 }
示例#14
0
 /**
  * Commits (either inserts or updates) the data for this DMRecord into the database.
  * @param boolean optional $ignoreMandatory If true, doesn't fail if mandatory
  *		fields don't have values.
  * @return bool
  */
 function commit($ignoreMandatory = false)
 {
     // Ensure that we have fields for all labels, incase
     // the schema has changed since we were loaded.
     foreach ($this->_schema->getAllLabels() as $label) {
         $this->_checkLabel($label);
     }
     // Get the DBHandler
     $dbHandler = Services::getService("DatabaseManager");
     // the first thing we're gonna do is check to make sure that all our required fields
     // have at least one value.
     if (!$this->_delete) {
         foreach ($this->_schema->getAllIDs() as $id) {
             $fieldDef = $this->_schema->getField($id);
             if ($fieldDef->isRequired() && ($this->_fields[$id]->numValues(true) == 0 || $this->_fields[$id]->numValues() == 0) && !$ignoreMandatory) {
                 throwError(new Error("Could not commit DMRecord to database because the required field '{$id}' does\n\t\t\t\t\tnot have any values!", "DMRecord", true));
                 return false;
             }
         }
         if ($this->_myID) {
             // we're already in the database
             $query = new UpdateQuery();
             $query->setTable("dm_record");
             $query->setColumns(array("ver_control"));
             $query->setValues(array($this->_versionControlled ? 1 : 0));
             $query->setWhere("id='" . addslashes($this->_myID) . "'");
         } else {
             // we'll have to make a new entry
             $schemaManager = Services::getService("SchemaManager");
             $newID = $this->_idManager->createId();
             $this->_myID = $newID->getIdString();
             $query = new InsertQuery();
             $query->setTable("dm_record");
             $query->setColumns(array("id", "fk_schema", "created", "ver_control"));
             $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($this->_schema->getID()) . "'", $dbHandler->toDBDate($this->_creationDate, DATAMANAGER_DBID), $this->_versionControlled ? 1 : 0));
         }
         // execute the query;
         $result = $dbHandler->query($query, DATAMANAGER_DBID);
         if (!$result) {
             throwError(new UnknownDBError("DMRecord"));
             return false;
         }
     }
     // now let's cycle through our FieldValues and commit them
     foreach ($this->_schema->getAllIDs() as $id) {
         $this->_fields[$id]->commit();
     }
     if ($this->_prune) {
         $constraint = $this->_pruneConstraint;
         // check if we have to delete any dataset tags based on our constraints
         $constraint->checkTags($this);
         $tagMgr = Services::getService("RecordTagManager");
         // if we are no good any more, delete ourselves completely
         if ($this->_delete) {
             // now, remove any tags from the DB that have to do with us, since they will no longer
             // be valid.
             $tagMgr->pruneTags($this);
             $query = new DeleteQuery();
             $query->setTable("dm_record");
             $query->setWhere("id='" . addslashes($this->getID()) . "'");
             $dbHandler->query($query, DATAMANAGER_DBID);
             $query = new DeleteQuery();
             $query->setTable("dm_record_set");
             $query->setWhere("fk_record='" . addslashes($this->getID()) . "'");
             $dbHandler->query($query, DATAMANAGER_DBID);
         } else {
             // if we're pruning but not deleting the whole shebang, let's
             // make sure that there are no tags in the database with no
             // mappings whatsoever.
             $tagMgr->checkForEmptyTags($this);
         }
     }
     return true;
 }
 /**
  * Add an Agent commitment to this ScheduleItem.
  * 
  * @param object Id $agentId
  * @param object Type $agentStatus
  * 
  * @throws object SchedulingException An exception with one of
  *         the following messages defined in
  *         org.osid.scheduling.SchedulingException may be thrown:   {@link
  *         org.osid.scheduling.SchedulingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.scheduling.SchedulingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.scheduling.SchedulingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.scheduling.SchedulingException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.scheduling.SchedulingException#UNKNOWN_ID UNKNOWN_ID},
  *         {@link org.osid.scheduling.SchedulingException#UNKNOWN_TYPE
  *         UNKNOWN_TYPE}, {@link
  *         org.osid.shared.SharedException#ALREADY_ADDED ALREADY_ADDED}
  * 
  * @access public
  */
 function addAgentCommitment(Id $agentId, Type $agentStatus)
 {
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('sc_commit');
     $query->addWhere("fk_sc_item='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'");
     $query->addColumn('id');
     //@TODO id is not really needed here--a count should probably be returned.
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         $typeIndex = $this->_typeToIndex('commit_stat', $agentStatus);
         $query = new InsertQuery();
         $query->setTable('sc_commit');
         $values[] = "'" . addslashes($agentId->getIdString()) . "'";
         $values[] = "'" . addslashes($typeIndex) . "'";
         $values[] = "'" . addslashes($this->_id->getIdString()) . "'";
         $query->setColumns(array('fk_agent_id', 'fk_sc_commit_stat_type', 'fk_sc_item'));
         $query->addRowOfValues($values);
         $query->setAutoIncrementColumn('id', 'id_sequence');
         $dbHandler->query($query);
     } else {
         print "<b>Warning!</b> Agent with id " . $agentId->getIdString() . "is already added to ScheduleItem " . $this->getDisplayName() . ".  Use changeAgentCommitment() to change the commitment status.";
     }
 }
 /**
  * Create a new Repository of the specified Type.  The implementation of
  * this method sets the Id for the new object.
  * 
  * @param string $displayName
  * @param string $description
  * @param object Type $repositoryType
  *  
  * @return object Repository
  * 
  * @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}, {@link
  *         org.osid.repository.RepositoryException#UNKNOWN_TYPE
  *         UNKNOWN_TYPE}
  * 
  * @access public
  */
 function createRepository($displayName, $description, Type $repositoryType, Id $id = NULL)
 {
     // Argument Validation
     ArgumentValidator::validate($displayName, StringValidatorRule::getRule());
     ArgumentValidator::validate($description, StringValidatorRule::getRule());
     ArgumentValidator::validate($repositoryType, ExtendsValidatorRule::getRule("Type"));
     // Create an Id for the digital Repository Node
     if (!is_object($id)) {
         $IDManager = Services::getService("Id");
         $id = $IDManager->createId();
     }
     // Store the type passed in our own table as we will be using
     // a special type, "repositoryKeyType", as definition of which
     // Nodes in the Hierarchy are Repositories.
     $dbc = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addColumn("type_id");
     $query->addTable("dr_type");
     $query->addWhere("type_domain = '" . addslashes($repositoryType->getDomain()) . "'");
     $query->addWhere("type_authority = '" . addslashes($repositoryType->getAuthority()) . "'", _AND);
     $query->addWhere("type_keyword = '" . addslashes($repositoryType->getKeyword()) . "'", _AND);
     $result = $dbc->query($query, $this->_dbIndex);
     if ($result->getNumberOfRows()) {
         $typeId = $result->field("type_id");
         $result->free();
     } else {
         $result->free();
         $query = new InsertQuery();
         $query->setTable("dr_type");
         $query->setAutoIncrementColumn("type_id", "dr_type_type_id_seq");
         $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description"));
         $query->setValues(array("'" . addslashes($repositoryType->getDomain()) . "'", "'" . addslashes($repositoryType->getAuthority()) . "'", "'" . addslashes($repositoryType->getKeyword()) . "'", "'" . addslashes($repositoryType->getDescription()) . "'"));
         $result = $dbc->query($query, $this->_dbIndex);
         $typeId = $result->getLastAutoIncrementValue();
     }
     $query = new InsertQuery();
     $query->setTable("dr_repository_type");
     $query->setColumns(array("repository_id", "fk_dr_type"));
     $query->setValues(array("'" . addslashes($id->getIdString()) . "'", "'" . addslashes($typeId) . "'"));
     $result = $dbc->query($query, $this->_dbIndex);
     // Add this DR's node to the hierarchy.
     // If we don't have a default parent specified, create
     // it as a root node
     if ($this->_defaultParentId == NULL) {
         $node = $this->_hierarchy->createRootNode($id, $this->repositoryKeyType, $displayName, $description);
     } else {
         $node = $this->_hierarchy->createNode($id, $this->_defaultParentId, $this->repositoryKeyType, $displayName, $description);
     }
     $this->_createdRepositories[$id->getIdString()] = new HarmoniRepository($this, $this->_hierarchy, $id, $this->_configuration);
     return $this->_createdRepositories[$id->getIdString()];
 }
示例#17
0
 /**
  * Reflects any changes made locally to the database.
  * @param optional int $id The ID in the database to update (if not adding...).
  * @return int Returns our ID in the database or NULL upon error.
  * @access public
  */
 function commit($id = null)
 {
     if (!$this->_schema->getID() || !$this->_addToDB && !$id) {
         // we have no ID, we probably can't commit...unless we're going to be added to the DB.
         // we'll also fail if our dataSetTypeDef doesn't have an ID. that meaning it wasn't meant to be
         // synchronized into the database.
         throwError(new Error("Could not commit() to database because either: 1) we don't have a local ID, \n\t\t\tmeaning we were not meant to be synchronized with the database, or 2) the Schema to which we \n\t\t\tbelong is not linked with the database. (label: " . $this->_label . ", schema name: " . $this->_schema->getDisplayName() . ")", "DataManager", true));
         return null;
     }
     $dbHandler = Services::getService("DatabaseManager");
     if ($this->_addToDB) {
         $query = new InsertQuery();
         $query->setTable("dm_schema_field");
         $query->setColumns(array("id", "fk_schema", "name", "mult", "fieldtype", "active", "required", "description"));
         $query->addRowOfValues(array("'" . addslashes($id) . "'", "'" . addslashes($this->_schema->getID()) . "'", "'" . addslashes($this->_displayName) . "'", $this->_mult ? 1 : 0, "'" . addslashes($this->_type) . "'", 1, $this->_required ? 1 : 0, "'" . addslashes($this->_description) . "'"));
         $this->_addToDB = false;
         $result = $dbHandler->query($query, DATAMANAGER_DBID);
         if (!$result || $result->getNumberOfRows() != 1) {
             throwError(new UnknownDBError("DataManager"));
             return false;
         }
         return $id;
     }
     if ($this->_update) {
         // do some updating
         $query = new UpdateQuery();
         $query->setTable("dm_schema_field");
         $query->setColumns(array("name", "mult", "active", "required", "description"));
         $query->setWhere("id='" . addslashes($id) . "'");
         $query->setValues(array("'" . addslashes($this->_displayName) . "'", $this->_mult ? 1 : 0, $this->_active ? 1 : 0, $this->_required ? 1 : 0, "'" . addslashes($this->_description) . "'"));
         $this->_update = false;
         $result = $dbHandler->query($query, DATAMANAGER_DBID);
         if (!$result || $result->getNumberOfRows() != 1) {
             throwError(new UnknownDBError("DataManager"));
             return null;
         }
         return $id;
     }
     if ($this->_delete) {
         // let's get rid of this bad-boy
         $query = new UpdateQuery();
         $query->setTable("dm_schema_field");
         $query->setWhere("id='" . addslashes($id) . "'");
         $query->setColumns(array("active"));
         $query->setValues(array(0));
         $this->_delete = false;
         $result = $dbHandler->query($query, DATAMANAGER_DBID);
         // 			if (!$result || $result->getNumberOfRows() != 1) {
         // 				throwError( new UnknownDBError("DataManager") );
         // 				return false;
         // 			}
         return $id;
     }
     // if we're here... nothing happened... no problems
     return $id;
 }
示例#18
0
 /**
  * Add a student to the roster and assign the specified Enrollment Status
  * Type.
  * 
  * @param object Id $agentId
  * @param object Type $enrollmentStatusType
  * 
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  *		   UNKNOWN_TYPE}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED
  *		   ALREADY_ADDED}
  * 
  * @access public
  */
 function addStudent(Id $agentId, Type $enrollmentStatusType)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addTable('cm_enroll');
     $query->addWhere("fk_cm_section='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_student_id='" . addslashes($agentId->getIdString()) . "'");
     //I don't need Id, but I need to select something for the query to work
     $query->addColumn('id');
     $res = $dbManager->query($query);
     if ($res->getNumberOfRows() == 0) {
         $typeIndex = $this->_typeToIndex('enroll_stat', $enrollmentStatusType);
         $query = new InsertQuery();
         $query->setTable('cm_enroll');
         $values[] = "'" . addslashes($agentId->getIdString()) . "'";
         $values[] = "'" . addslashes($typeIndex) . "'";
         $values[] = "'" . addslashes($this->_id->getIdString()) . "'";
         $query->setColumns(array('fk_student_id', 'fk_cm_enroll_stat_type', 'fk_cm_section'));
         $query->addRowOfValues($values);
         $query->setAutoIncrementColumn('id', 'id_sequence');
         $dbManager->query($query);
     } else {
         print "<b>Warning!</b> Student with id " . $agentId->getIdString() . " is already enrolled in section " . $this->getDisplayName() . ".";
     }
 }
 /**
  * Find the index for our Type of type $type in its table.  If it is not there,
  * put it into the table and return the index.
  *
  * @param string $typename the type of Type that is passed in.
  * @param object Type $type the Type itself
  *
  * @return object Type
  *
  * @access private
  */
 function _typeToIndex($typename, $type)
 {
     //the appropriate table names and fields must be given names according to the pattern indicated below
     //validate the Type
     ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true);
     //query to see if it exists
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('cm_' . $typename . "_type");
     $query->addWhere("domain='" . $type->getDomain() . "'");
     $query->addWhere("authority='" . $type->getAuthority() . "'");
     $query->addWhere("keyword='" . $type->getKeyword() . "'");
     $query->addColumn('id');
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         //if not query to create it
         $query = new InsertQuery();
         $query->setTable('cm_' . $typename . '_type');
         $values[] = "'" . addslashes($type->getDomain()) . "'";
         $values[] = "'" . addslashes($type->getAuthority()) . "'";
         $values[] = "'" . addslashes($type->getKeyword()) . "'";
         if (is_null($type->getDescription())) {
             $query->setColumns(array('domain', 'authority', 'keyword'));
         } else {
             $query->setColumns(array('domain', 'authority', 'keyword', 'description'));
             $values[] = "'" . addslashes($type->getDescription()) . "'";
         }
         $query->addRowOfValues($values);
         $query->setAutoIncrementColumn('id', 'cm_' . $typename . '_type_id_seq');
         $result = $dbHandler->query($query);
         return $result->getLastAutoIncrementValue();
     } elseif ($res->getNumberOfRows() == 1) {
         //if it does exist, create it
         $row = $res->getCurrentRow();
         $the_index = $row['id'];
         return $the_index;
     } else {
         //print a warning if there is more than one such type.  Should never happen.
         print "\n<b>Warning!<\\b> The Type with domain " . $type->getDomain() . ", authority " . $type->getAuthority() . ", and keyword " . $type->getKeyword() . " is not unique--there are " . $res->getNumberOfRows() . " copies.\n";
         //return either one anyway.
         $row = $res->getCurrentRow();
         $the_index = $row['id'];
         return $the_index;
     }
 }
 /**
  * Creates a new Authorization object, caches it, and inserts it into the database.
  * @access public
  * @param ref object agentId who is authorized to perform this Function for this Qualifer and its descendants
  * @param ref object functionId the Id of the Function for this Authorization
  * @param ref object qualifierId the Id of the Qualifier for this Authorization
  * @param object DateAndTime effectiveDate when the Authorization becomes effective
  * @param object DateAndTime expirationDate when the Authorization stops being effective
  * @return ref object Authorization
  **/
 function createAuthorization(Id $agentId, Id $functionId, Id $qualifierId, $effectiveDate = NULL, $expirationDate = NULL)
 {
     // ** parameter validation
     ArgumentValidator::validate($effectiveDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true);
     ArgumentValidator::validate($expirationDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true);
     // ** end of parameter validation
     // create the authorization object
     $idManager = Services::getService("Id");
     $id = $idManager->createId();
     $idValue = $id->getIdString();
     // figure out whether it's dated or not
     $dated = isset($effectiveDate) && isset($expirationDate);
     if ($dated) {
         $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $qualifierId, true, $this, $effectiveDate, $expirationDate);
     } else {
         $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $qualifierId, true, $this);
     }
     $dbHandler = Services::getService("DatabaseManager");
     if (isset($this->harmoni_db)) {
         if (!isset($this->createAZ_stmt)) {
             $query = $this->harmoni_db->insert();
             $query->setTable("az_authorization");
             $query->addRawValue("authorization_id", "?");
             $query->addRawValue("fk_agent", "?");
             $query->addRawValue("fk_function", "?");
             $query->addRawValue("fk_qualifier", "?");
             $query->addRawValue("authorization_effective_date", "?");
             $query->addRawValue("authorization_expiration_date", "?");
             $this->createAZ_stmt = $query->prepare();
         }
         $this->createAZ_stmt->bindValue(1, $idValue);
         $this->createAZ_stmt->bindValue(2, $agentId->getIdString());
         $this->createAZ_stmt->bindValue(3, $functionId->getIdString());
         $this->createAZ_stmt->bindValue(4, $qualifierId->getIdString());
         if (is_object($effectiveDate)) {
             $this->createAZ_stmt->bindValue(5, $dbHandler->toDBDate($effectiveDate, $this->_dbIndex));
         } else {
             $this->createAZ_stmt->bindValue(5, null);
         }
         if (is_object($expirationDate)) {
             $this->createAZ_stmt->bindValue(6, $dbHandler->toDBDate($expirationDate, $this->_dbIndex));
         } else {
             $this->createAZ_stmt->bindValue(6, null);
         }
         // 			try {
         $this->createAZ_stmt->execute();
         // 			} catch (Zend_Db_Statement_Exception $e) {
         // 				throw new OperationFailedException("An Explicit Authorization already exists for '$agentId' to '$functionId' at '$qualifierId'");
         // 			}
     } else {
         // now insert into database
         $dbHandler = Services::getService("DatabaseManager");
         $query = new InsertQuery();
         $query->setTable("az_authorization");
         $columns = array();
         $columns[] = "authorization_id";
         $columns[] = "fk_agent";
         $columns[] = "fk_function";
         $columns[] = "fk_qualifier";
         if ($dated) {
             $columns[] = "authorization_effective_date";
             $columns[] = "authorization_expiration_date";
         }
         $query->setColumns($columns);
         $values = array();
         $values[] = "'" . addslashes($idValue) . "'";
         $values[] = "'" . addslashes($agentId->getIdString()) . "'";
         $values[] = "'" . addslashes($functionId->getIdString()) . "'";
         $values[] = "'" . addslashes($qualifierId->getIdString()) . "'";
         if ($dated) {
             if (is_object($effectiveDate)) {
                 $values[] = $dbHandler->toDBDate($effectiveDate, $this->_dbIndex);
             } else {
                 $values[] = "NULL";
             }
             if (is_object($expirationDate)) {
                 $values[] = $dbHandler->toDBDate($expirationDate, $this->_dbIndex);
             } else {
                 $values[] = "NULL";
             }
         }
         $query->setValues($values);
         try {
             $dbHandler->query($query, $this->_dbIndex);
         } catch (DuplicateKeyDatabaseException $e) {
             throw new OperationFailedException("An Explicit Authorization already exists for '{$agentId}' to '{$functionId}' at '{$qualifierId}'");
         }
     }
     $this->_authorizations[$idValue] = $authorization;
     return $authorization;
 }
 /**
  * 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)
 {
     $file = $this->_getFilePath();
     if (!($handle = fopen($file, 'w'))) {
         throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be opened for writing.", "FileSystemFileDataPart", true));
     }
     if (fwrite($handle, $value) === FALSE) {
         fclose($handle);
         throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be written to.", "FileSystemFileDataPart", true));
     }
     fclose($handle);
     // Check to see if the size is in the database
     $dbHandler = Services::getService("DatabaseManager");
     $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");
         $query->setColumns(array("size"));
         $query->setValues(array("'" . strlen($value) . "'"));
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("id", "size"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . strlen($value) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
示例#22
0
 /**
  * Saves the style components of a style property
  *
  * @param object StyleCollection $property
  * @return void
  * @access public
  * @since 4/26/06
  */
 function saveStyleComponentsForProperty($property)
 {
     // get the style components for the property
     $dbHandler = Services::getService("DatabaseManager");
     $styleComponents = $property->getSCs();
     foreach ($styleComponents as $styleComponent) {
         $id = $styleComponent->getId();
         $idValue = $id->getIdString();
         $query = new SelectQuery();
         $query->addTable($this->_dbName . ".tm_style_component");
         $query->addWhere('component_id = ' . $idValue);
         $query->addColumn("component_id");
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
         if ($queryResult->getNumberOfRows() > 1) {
             throwError(new Error("GUIManager", "component id multiplicity"));
         } else {
             if ($queryResult->getNumberOfRows() == 1) {
                 $queryResult->free();
                 $query = new UpdateQuery();
                 $query->setWhere("component_id = {$idValue}");
             } else {
                 $queryResult->free();
                 $query = new InsertQuery();
             }
         }
         $query->setTable($this->_dbName . ".tm_style_component");
         $query->setColumns(array('component_id', 'component_class_name', 'component_value'));
         $query->setValues(array("'" . addslashes($idValue) . "'", "'" . addslashes(get_class($styleComponent)) . "'", "'" . addslashes($styleComponent->getValue()) . "'"));
         $dbHandler->query($query, $this->_dbIndex);
         // save the style properties for this theme
     }
 }
 function test_All_Queries()
 {
     $value = "'Depeche Mode rocks!'";
     $this->dbhandler->connect();
     // create a new queue of queries to execuete
     $queryQueue = new Queue();
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array($value));
     $queryQueue->add($query);
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array(id, value));
     $query->addRowOfValues(array("3000000", $value));
     $queryQueue->add($query);
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->setWhere("id = 3000000");
     $queryQueue->add($query);
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array($value));
     $query->setWhere("id > 1000 AND id < 1006");
     $queryQueue->add($query);
     $resultQueue = $this->dbhandler->queryQueue($queryQueue);
     $this->assertEqual($this->dbhandler->getTotalNumberOfQueries(), 4);
     $this->assertEqual($this->dbhandler->getTotalNumberOfSuccessfulQueries(), 4);
     $this->assertEqual($this->dbhandler->getTotalNumberOfFailedQueries(), 0);
     $result = $resultQueue->next();
     $this->assertEqual($result->getNumberOfRows(), 1);
     $this->assertNotNull($result->getLastAutoIncrementValue());
     $id = $result->getLastAutoIncrementValue();
     $result = $resultQueue->next();
     $this->assertEqual($result->getNumberOfRows(), 1);
     $this->assertNotNull($result->getLastAutoIncrementValue());
     $result = $resultQueue->next();
     $this->assertEqual($result->getNumberOfRows(), 1);
     $result = $resultQueue->next();
     $query = new SelectQuery();
     $query->setColumns(array("value"));
     $query->addTable("test1");
     $query->setWhere("id = {$id}");
     $result = $this->dbhandler->query($query);
     $this->assertEqual($this->dbhandler->getTotalNumberOfQueries(), 5);
     $this->assertEqual($this->dbhandler->getTotalNumberOfSuccessfulQueries(), 5);
     $this->assertEqual($this->dbhandler->getTotalNumberOfFailedQueries(), 0);
     $this->assertEqual("'" . $result->field("value") . "'", $value);
     $result->free();
 }
 /**
  * Get the key of the type.
  * 
  * @param object Type $type
  * @return integer
  * @access private
  * @since 3/9/05
  */
 function _getTypeKey(Type $type)
 {
     $dbc = Services::getService("DatabaseManager");
     // Check if the type exists and return its key if found.
     $query = new SelectQuery();
     $query->addTable($this->_typeTable);
     $query->addColumn('id');
     $query->addWhere("domain='" . addslashes($type->getDomain()) . "'");
     $query->addWhere("authority='" . addslashes($type->getAuthority()) . "'", _AND);
     $query->addWhere("keyword='" . addslashes($type->getKeyword()) . "'", _AND);
     $result = $dbc->query($query, $this->_dbId);
     if ($result->getNumberOfRows() == 1) {
         return $result->field('id');
     } else {
         $result->free();
         $query = new InsertQuery();
         $query->setTable($this->_typeTable);
         $query->setAutoIncrementColumn("id", $this->_typeTable . "_id_seq");
         $query->setColumns(array('domain', 'authority', 'keyword', 'description'));
         $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
         $result = $dbc->query($query, $this->_dbId);
         return $result->getLastAutoIncrementValue();
     }
 }
 /**
  * Tests the generateSQLQuery() without WHERE clause.
  */
 function test()
 {
     // insert one row
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array("'Spaceboy'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     $lastId = $result->getLastAutoIncrementValue();
     // insert it again, the id must have increased by one
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 1);
     // add several rows at the same time
     $query->addRowOfValues(array("'Astrogirl'"));
     $result = $this->db->query($query);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 3);
     // now insert in the other test table
     $query = new InsertQuery();
     $query->setTable("test");
     $query->setColumns(array("FK", "value"));
     $query->addRowOfValues(array($lastId, "'Ziggy'"));
     $query->addRowOfValues(array($lastId + 1, "'Lost in the Stars'"));
     $query->addRowOfValues(array($lastId + 2, "'Headstar'"));
     $query->addRowOfValues(array($lastId + 3, "'Stardust'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     // join the inserted rows
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addTable("test", INNER_JOIN, "test.FK = test1.id");
     $query->addColumn("id", "dm86_id", "test");
     $query->addColumn("FK", "dm86_fk", "test");
     $query->addColumn("value", "dm86_value", "test");
     $query->addColumn("id", "dm98_id", "test1");
     $query->addColumn("value", "dm98_value", "test1");
     $query->addWhere("test1.id >= " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 4);
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId);
     $this->assertIdentical($result->field("dm86_value"), "Ziggy");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 1);
     $this->assertIdentical($result->field("dm86_value"), "Lost in the Stars");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 1);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 2);
     $this->assertIdentical($result->field("dm86_value"), "Headstar");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 2);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 3);
     $this->assertIdentical($result->field("dm86_value"), "Stardust");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 3);
     $this->assertIdentical($result->field("dm98_value"), "Astrogirl");
     $result->free();
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array("'I changed you MF!'"));
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->field("value"), "I changed you MF!");
     $result->free();
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 0);
     $result->free();
 }
 /**
  * Answer the database id for the type passed.
  * 
  * @param object Type $type
  * @return string
  * @access public
  * @since 3/1/06
  */
 function _getTypeId(Type $type)
 {
     if (!isset($this->_typeIds)) {
         $this->_typeIds = array();
     }
     if (!isset($this->_typeIds[$type->asString()])) {
         $dbc = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addColumn("id");
         $query->addTable("log_type");
         $query->addWhere("domain = '" . addslashes($type->getDomain()) . "'");
         $query->addWhere("authority = '" . addslashes($type->getAuthority()) . "'");
         $query->addWhere("keyword = '" . addslashes($type->getKeyword()) . "'");
         $results = $dbc->query($query, $this->_dbIndex);
         if ($results->getNumberOfRows()) {
             $this->_typeIds[$type->asString()] = $results->field("id");
             $results->free();
         } else {
             $results->free();
             $query = new InsertQuery();
             $query->setTable("log_type");
             $query->setAutoIncrementColumn("id", "log_type_id_seq");
             $query->setColumns(array("domain", "authority", "keyword", "description"));
             $query->addRowOfValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
             $results = $dbc->query($query, $this->_dbIndex);
             $this->_typeIds[$type->asString()] = $results->getLastAutoIncrementValue();
         }
     }
     return $this->_typeIds[$type->asString()];
 }
 /**
  * Attempts to commit our {@link DMRecord}s to the database and update our mapping.
  * @param boolean optional $ignoreMandatory If true, doesn't fail if mandatory
  *		fields don't have values.
  * @return void
  */
 function commit($ignoreMandatory = false)
 {
     $ids = array();
     if (count($this->_records)) {
         for ($i = 0; $i < count($this->_records); $i++) {
             $this->_records[$i]->commit($ignoreMandatory);
             $ids[] = $this->_records[$i]->getID();
         }
         $this->_records = array();
         $this->_fetchMode = -1;
     }
     if ($this->_dirty) {
         // syncrhonize the database
         $ids = array_merge($ids, $this->_storedRecordIDs);
         // Make sure that we only have one ID for each record.
         $ids = array_unique($ids);
         $dbHandler = Services::getService("DatabaseManager");
         // first delete all the old mappings
         $query = new DeleteQuery();
         $query->setTable("dm_record_set");
         $query->setWhere("dm_record_set.id='" . addslashes($this->_myID) . "'");
         //			printpre(MySQL_SQLGenerator::generateSQLQuery($query));
         $dbHandler->query($query, DATAMANAGER_DBID);
         if (count($ids)) {
             // next insert all our mappings back in.
             $query = new InsertQuery();
             $query->setTable("dm_record_set");
             $query->setColumns(array("id", "fk_record"));
             foreach ($ids as $id) {
                 $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($id) . "'"));
                 if (!in_array($id, $this->_storedRecordIDs)) {
                     $this->_storedRecordIDs[] = $id;
                 }
             }
             //				printpre(MySQL_SQLGenerator::generateSQLQuery($query));
             $dbHandler->query($query, DATAMANAGER_DBID);
             // done!
         }
     }
 }
 /**
  * Add a PartStructureId for which Tags should be auto-generated, in the
  * given repository
  * 
  * @param object Id $repositoryId
  * @param object Id $partStructureId
  * @return void
  * @access public
  * @since 11/21/06
  */
 function addPartStructureIdForTagGeneration($repositoryId, $partStructureId)
 {
     if ($this->shouldGenerateTagsForPartStructure($repositoryId, $partStructureId)) {
         return;
     }
     // Insert it into the database
     $query = new InsertQuery();
     $query->setColumns(array('fk_repository', 'fk_partstruct'));
     $query->addRowOfValues(array("'" . addslashes($repositoryId->getIdString()) . "'", "'" . addslashes($partStructureId->getIdString()) . "'"));
     $query->setTable('tag_part_map');
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     // Add it to the cache
     $this->_cache[$repositoryId->getIdString()][] = $partStructureId;
 }
示例#29
0
 /**
  * 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)
 {
     //		ArgumentValidator::validate($value, StringValidatorRule::getRule());
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the row if we are setting the value to null
     if (is_null($value)) {
         $query = new DeleteQuery();
         $query->setTable("dr_file_data");
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         $this->_asset->updateModificationDate();
         return;
     }
     // Store the data in the object in case its asked for again.
     //		$this->_data = $value;
     // Make sure that the dr_file row is inserted.
     $query = new InsertQuery();
     $query->setTable("dr_file");
     $query->addValue("id", $this->_recordId->getIdString());
     try {
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     } catch (QueryDatabaseException $e) {
         // If an error is thrown inserting (because the file already exists)
         // ignore it.
     }
     $dbHandler->beginTransaction($this->_configuration->getProperty("database_index"));
     // Base64 encode the data to preserve it,
     // then write it to the database.
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_data");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("fk_file = '" . $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_data");
         $query->setColumns(array("data"));
         $query->setValues(array("'" . base64_encode($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("fk_file", "data"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . base64_encode($value) . "'"));
     }
     $result->free();
     //		printpre($query);
     //		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // Update the size row.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->addValue("size", strval(strlen($value)));
     $query->addWhereEqual("id", $this->_recordId->getIdString());
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $dbHandler->commitTransaction($this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 /**
  * Commits any changes that have been made to the database. If neither update() nor prune() have been
  * called, even if changes have been made, they will not be reflected in the database.
  * @return bool
  * @access public
  */
 function commit()
 {
     $dbHandler = Services::getService("DatabaseManager");
     if ($this->_update) {
         // let's re-cast our primitive to a storablePrimitive
         $this->recastAsStorable();
         // first we need to commit the actual Primitive value
         // so that we can get its ID
         if (!$this->_dataID) {
             $this->_dataID = $this->_primitive->insert(DATAMANAGER_DBID);
         } else {
             $this->_primitive->update(DATAMANAGER_DBID, $this->_dataID);
         }
         $this->_date = DateAndTime::now();
         if ($this->_myID) {
             // we're already in the DB. just update the entry
             $query = new UpdateQuery();
             $query->setWhere("id='" . addslashes($this->_myID) . "'");
             $query->setColumns(array("value_index", "active", "modified"));
             $query->setValues(array($this->_parent->getIndex(), $this->_active ? 1 : 0, $dbHandler->toDBDate($this->_date, DATAMANAGER_DBID)));
         } else {
             // we have to insert a new one
             $query = new InsertQuery();
             $idManager = Services::getService("Id");
             $newID = $idManager->createId();
             $this->_myID = $newID->getIdString();
             $query->setColumns(array("id", "fk_record", "fk_schema_field", "value_index", "fk_data", "active", "modified"));
             $schema = $this->_parent->_parent->_parent->getSchema();
             $schemaField = $this->_parent->_parent->getSchemaField();
             $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($this->_parent->_parent->_parent->getID()) . "'", "'" . addslashes($schemaField->getID()) . "'", $this->_parent->getIndex(), "'" . addslashes($this->_dataID) . "'", $this->_active ? 1 : 0, $dbHandler->toDBDate($this->_date, DATAMANAGER_DBID)));
         }
         $query->setTable("dm_record_field");
         $result = $dbHandler->query($query, DATAMANAGER_DBID);
         if (!$result) {
             throwError(new UnknownDBError("DMRecord"));
             return false;
         }
     }
     if ($this->_prune && $this->_dataID) {
         if ($id = $this->getID()) {
             // ok, let's get rid of ourselves... completely!
             $query = new DeleteQuery();
             $query->setTable("dm_record_field");
             $query->setWhere("id='" . addslashes($id) . "'");
             $res = $dbHandler->query($query, DATAMANAGER_DBID);
             if (!$res) {
                 throwError(new UnknownDBError("DMRecord"));
             }
             // now tell the data object to prune itself
             $this->recastAsStorable();
             $this->_primitive->prune(DATAMANAGER_DBID, $this->_dataID);
             // and we have to get rid of any tag mappings where we are included.
             $query = new DeleteQuery();
             $query->setTable("dm_tag_map");
             $query->setWhere("fk_record_field='" . addslashes($id) . "'");
             $res = $dbHandler->query($query, DATAMANAGER_DBID);
             if (!$res) {
                 throwError(new UnknownDBError("DMRecord"));
             }
         }
     }
     // reset the prune flag
     $this->_prune = false;
     // reset the update flag
     $this->_update = false;
     return true;
 }