Exemplo n.º 1
0
 /**
  * Add this tag to an Item for a particular agent
  * 
  * @param object TaggedItem $item
  * @param object Id $agentId
  * @param optional object DateAndTime $date An optional timestamp, used for importing historical tags.
  * @return object The item
  * @access public
  * @since 11/6/06
  */
 function tagItemForAgent(TaggedItem $item, Id $agentId, DateAndTime $date = null)
 {
     // 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->addValue('value', $this->getValue());
     $query->addValue('user_id', $agentId->getIdString());
     $query->addValue('fk_item', $item->getDatabaseId());
     //printpre("'".addslashes($item->getDatabaseId())."'"))
     if (!is_null($date)) {
         $query->addValue('tstamp', $date->asString());
     }
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     return $item;
 }
 /**
  * Add an External group to a Hierarchy-based group.
  * 
  * @param object Id $hierarchyParentId
  * @param object Id $externalChildId
  * @return void
  * @access public
  * @since 11/6/07
  */
 public function addExternalChildGroup(Id $hierarchyParentId, Id $externalChildId)
 {
     // Check to see that it hasn't been added.
     $children = $this->getExternalChildGroupIds($hierarchyParentId);
     foreach ($children as $child) {
         if ($externalChildId->isEqual($child)) {
             throw new HarmoniException("Child group '" . $externalChildId->getIdString() . "' has already been added to group '" . $hierarchyParentId->getIdString() . "'.");
         }
     }
     // Insert the row.
     $query = new InsertQuery();
     $query->setTable('agent_external_children');
     $query->addValue('fk_parent', $hierarchyParentId->getIdString());
     $query->addValue('fk_child', $externalChildId->getIdString());
     $dbc = Services::getService("DBHandler");
     $dbc->query($query, $this->_configuration->getProperty('database_index'));
 }
Exemplo n.º 3
0
 /**
  * Save an XML string to the feed cache
  * 
  * @param string $url
  * @param string $feedXml
  * @return void
  * @access protected
  * @since 7/8/08
  */
 protected function cacheXmlString($url, $feedXml)
 {
     $dbc = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addWhereEqual('url', $url);
     $query->addWhereRawLessThan('cache_time', $dbc->toDBDate(DateAndTime::now()->minus(Duration::withSeconds(600)), IMPORTER_CONNECTION), _OR);
     try {
         $result = $dbc->query($query, IMPORTER_CONNECTION);
     } catch (NoSuchTableDatabaseException $e) {
         $this->createCacheTable();
     }
     $query = new InsertQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addValue('url', $url);
     $query->addValue('feed_data', $feedXml);
     $dbc->query($query, IMPORTER_CONNECTION);
 }
Exemplo n.º 4
0
 /**
  * Attempts to create the specified node as root node in the database.
  * @access public
  * @param object nodeId The id of the node.
  * @param object type The type of the node.
  * @param string displayName The display name of the node.
  * @param string description The description of the node.
  * @return void
  **/
 function createRootNode(Id $nodeId, Type $type, $displayName, $description)
 {
     // ** parameter validation
     $stringRule = StringValidatorRule::getRule();
     ArgumentValidator::validate($displayName, $stringRule, true);
     ArgumentValidator::validate($description, $stringRule, true);
     // ** end of parameter validation
     // check that the node does not exist in the cache
     $idValue = $nodeId->getIdString();
     if ($this->_isCached($idValue)) {
         // The node has already been cached!
         throw new OperationFailedException("Node, '{$idValue}' is already cached.");
     }
     // attempt to insert the node now
     $dbHandler = Services::getService("DatabaseManager");
     // 1. Insert the type
     $domain = $type->getDomain();
     $authority = $type->getAuthority();
     $keyword = $type->getKeyword();
     $typeDescription = $type->getDescription();
     // check whether the type is already in the DB, if not insert it
     if (isset($this->harmoni_db)) {
         if (!isset($this->createRootNode_selectType_stmt)) {
             $query = $this->harmoni_db->select();
             $query->addTable("az2_node_type");
             $query->addColumn("id");
             $query->addWhereRawEqual("domain", '?');
             $query->addWhereRawEqual("authority", '?');
             $query->addWhereRawEqual("keyword", '?');
             $this->createRootNode_selectType_stmt = $query->prepare();
         }
         $this->createRootNode_selectType_stmt->bindValue(1, $domain);
         $this->createRootNode_selectType_stmt->bindValue(2, $authority);
         $this->createRootNode_selectType_stmt->bindValue(3, $keyword);
         $this->createRootNode_selectType_stmt->execute();
         $queryResult = $this->createRootNode_selectType_stmt->getResult();
     } else {
         $query = new SelectQuery();
         $query->addTable("az2_node_type");
         $query->addColumn("id");
         $query->addWhereEqual("domain", $domain);
         $query->addWhereEqual("authority", $authority);
         $query->addWhereEqual("keyword", $keyword);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
     }
     if ($queryResult->hasNext()) {
         // if the type is already in the database
         $typeIdValue = $queryResult->field("id");
         // get the id
         $queryResult->free();
     } else {
         // if not, insert it
         $queryResult->free();
         if (isset($this->harmoni_db)) {
             if (!isset($this->createRootNode_insertType_stmt)) {
                 $query = $this->harmoni_db->insert();
                 $query->setTable("az2_node_type");
                 // 					$query->setAutoIncrementColumn("id", "az2_node_type_id_seq");
                 $query->addRawValue("domain", '?');
                 $query->addRawValue("authority", '?');
                 $query->addRawValue("keyword", '?');
                 $query->addRawValue("description", '?');
                 $this->createRootNode_insertType_stmt = $query->prepare();
             }
             $this->createRootNode_insertType_stmt->bindValue(1, $domain);
             $this->createRootNode_insertType_stmt->bindValue(2, $authority);
             $this->createRootNode_insertType_stmt->bindValue(3, $keyword);
             $this->createRootNode_insertType_stmt->bindValue(4, $typeDescription);
             $this->createRootNode_insertType_stmt->execute();
             $queryResult = $this->createRootNode_insertType_stmt->getResult();
         } else {
             $query = new InsertQuery();
             $query->setTable("az2_node_type");
             $query->setAutoIncrementColumn("id", "az2_node_type_id_seq");
             $query->addValue("domain", $domain);
             $query->addValue("authority", $authority);
             $query->addValue("keyword", $keyword);
             $query->addValue("description", $typeDescription);
             $queryResult = $dbHandler->query($query, $this->_dbIndex);
         }
         $typeIdValue = $queryResult->getLastAutoIncrementValue();
     }
     // 2. Now that we know the id of the type, insert the node itself
     if (isset($this->harmoni_db)) {
         if (!isset($this->createRootNode_insertNode_stmt)) {
             $query = $this->harmoni_db->insert();
             $query->setTable("az2_node");
             $query->addRawValue("id", '?');
             $query->addRawValue("display_name", '?');
             $query->addRawValue("description", '?');
             $query->addRawValue("fk_hierarchy", '?');
             $query->addRawValue("fk_type", '?');
             $this->createRootNode_insertNode_stmt = $query->prepare();
         }
         $this->createRootNode_insertNode_stmt->bindValue(1, $idValue);
         $this->createRootNode_insertNode_stmt->bindValue(2, $displayName);
         $this->createRootNode_insertNode_stmt->bindValue(3, $description);
         $this->createRootNode_insertNode_stmt->bindValue(4, $this->_hierarchyId);
         $this->createRootNode_insertNode_stmt->bindValue(5, $typeIdValue);
         $this->createRootNode_insertNode_stmt->execute();
         $queryResult = $this->createRootNode_insertNode_stmt->getResult();
     } else {
         $query = new InsertQuery();
         $query->setTable("az2_node");
         $query->addValue("id", $idValue);
         $query->addValue("display_name", $displayName);
         $query->addValue("description", $description);
         $query->addValue("fk_hierarchy", $this->_hierarchyId);
         $query->addValue("fk_type", $typeIdValue);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
     }
     if ($queryResult->getNumberOfRows() != 1) {
         //"Could not insert the node (it already exists?)";
         throw new OperationFailedException($queryResult->getNumberOfRows() . " nodes found. Expecting 1. Node already exists?");
     }
     // create the node object to return
     $node = new AuthZ2_Node($nodeId, $type, $displayName, $description, $this);
     // then cache it
     $this->_cache[$idValue][0] = $node;
     $this->_cache[$idValue][1] = -1;
     // fully cached up and down because
     $this->_cache[$idValue][2] = -1;
     // in fact this node does not have any ancestors or descendents
     // update _tree
     $nullValue = NULL;
     // getting rid of PHP warnings by specifying
     // this second argument
     $this->_tree->addNode(new TreeNode($idValue), $nullValue);
     return $node;
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
0
 /**
  * Create a new empty theme.
  * 
  * @return object Harmoni_Gui2_ThemeInterface
  * @access public
  * @since 5/16/08
  */
 public function createTheme()
 {
     $query = new InsertQuery();
     $query->setTable('segue_site_theme');
     $query->addValue('fk_site', $this->getSiteId());
     $query->addValue('display_name', _("Untitled"));
     $dbc = Services::getService('DatabaseManager');
     $result = $dbc->query($query, $this->databaseIndex);
     return new Segue_Gui2_SiteTheme($this->databaseIndex, strval($result->getLastAutoIncrementValue()));
 }
Exemplo n.º 8
0
 /**
  * Convert a slot to another type. The object passed on will no longer be valid.
  * 
  * @param object Slot $slot
  * @param string $type
  * @return object Slot
  * @access public
  * @since 1/4/08
  */
 public function convertSlotToType(Slot $slot, $type)
 {
     if (!isset($this->slotTypes[$type])) {
         throw new Exception("Unknown SlotType, '{$type}'. Should be one of (" . implode(", ", array_keys($this->slotTypes)) . ").");
     }
     $shortname = $slot->getShortname();
     $dbc = Services::getService("DatabaseManager");
     try {
         // Add a row to the slot table
         $query = new InsertQuery();
         $query->setTable('segue_slot');
         $query->addValue('shortname', $shortname);
         if ($slot->getSiteId()) {
             $query->addValue('site_id', $slot->getSiteId()->getIdString());
         }
         if ($slot->isAlias()) {
             $query->addValue('alias_target', $slot->getAliasTarget()->getShortname());
         }
         $query->addValue('type', $type);
         $query->addValue('location_category', $slot->getLocationCategory());
         if (!$slot->usesDefaultMediaQuota()) {
             $query->addValue('media_quota', $slot->getMediaQuota());
         }
         $dbc->query($query, IMPORTER_CONNECTION);
     } catch (DuplicateKeyDatabaseException $e) {
         // Update row to the slot table
         $query = new UpdateQuery();
         $query->setTable('segue_slot');
         $query->addWhereEqual('shortname', $shortname);
         $query->addValue('type', $type);
         $dbc->query($query, IMPORTER_CONNECTION);
     }
     // Clear our cache
     unset($this->slots[$shortname]);
     $slot = $this->getSlotByShortname($shortname);
     return $slot;
 }
Exemplo n.º 9
0
 /**
  * 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;
     }
 }
Exemplo n.º 10
0
 /**
  * Record a visit in the database
  * 
  * @param string $slotname
  * @param string $timestamp
  * @return void
  * @access protected
  * @since 9/22/08
  */
 protected function _recordPastVisit($slotname, $timestamp)
 {
     $dbc = Services::getService('DatabaseManager');
     // First try running an update query, since most will be updates
     $query = new UpdateQuery();
     $query->setTable('segue_accesslog');
     $query->addValue('tstamp', $timestamp);
     $query->addWhereEqual('agent_id', $this->_getCurrentAgentId());
     $query->addWhereEqual('fk_slotname', $slotname);
     $query->addWhereLessThan('tstamp', $timestamp);
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     // If no rows were updated, insert a new one for this user/slot
     if (!$result->getNumberOfRows()) {
         try {
             $query = new InsertQuery();
             $query->setTable('segue_accesslog');
             $query->addValue('tstamp', $timestamp);
             $query->addValue('agent_id', $this->_getCurrentAgentId());
             $query->addValue('fk_slotname', $slotname);
             $dbc->query($query, IMPORTER_CONNECTION);
             // If the update query failed the more recent time where clause,
             // this insert query will fail. That is fine, just ignore.
         } catch (DuplicateKeyDatabaseException $e) {
         }
     }
 }
 /**
  * Import a historical version, for instance from a backup system.
  * 
  * @param object DOMDocument $versionXml The version markup.
  * @param object Id $agentId The agent id that created the version.
  * @param object DateAndTime $timestamp The time the version was created.
  * @param string $comment A comment associated with the version.
  * @return void
  * @access public
  * @since 1/23/08
  */
 public function importVersion(DOMDocument $versionXml, Id $agentId, DateAndTime $timestamp, $comment)
 {
     $query = new InsertQuery();
     $query->setTable('segue_plugin_version');
     $query->addValue('node_id', $this->getId());
     $query->addValue('tstamp', $timestamp->asString());
     $query->addValue('agent_id', $agentId->getIdString());
     $query->addValue('comment', $comment);
     $query->addValue('version_xml', $versionXml->saveXML());
     $dbc = Services::getService('DBHandler');
     $dbc->query($query, IMPORTER_CONNECTION);
     unset($this->versions);
 }
Exemplo n.º 12
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.
     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();
 }
Exemplo n.º 13
0
 /**
  * Creates a new Function, insertsi in the DB and caches it.
  * @param ref object functionId is externally defined
  * @param string displayName the name to display for this Function
  * @param string description the description of this Function
  * @param ref object functionType the Type of this Function
  * @param ref object qualifierHierarchyId the Id of the Qualifier Hierarchy associated with this Function
  * @return ref object Function
  */
 function createFunction($functionId, $displayName, $description, $functionType, $qualifierHierarchyId)
 {
     // ** parameter validation
     ArgumentValidator::validate($functionId, ExtendsValidatorRule::getRule("Id"), true);
     ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
     ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
     ArgumentValidator::validate($functionType, ExtendsValidatorRule::getRule("Type"), true);
     ArgumentValidator::validate($qualifierHierarchyId, ExtendsValidatorRule::getRule("Id"), true);
     // ** end of parameter validation
     // create the Function object
     $idManager = Services::getService("Id");
     $function = new HarmoniFunction($functionId, $displayName, $description, $functionType, $qualifierHierarchyId, $this->_dbIndex);
     // now insert into database
     $dbHandler = Services::getService("DatabaseManager");
     $idValue = $functionId->getIdString();
     // 1. Insert the type
     $domain = $functionType->getDomain();
     $authority = $functionType->getAuthority();
     $keyword = $functionType->getKeyword();
     $functionTypeDescription = $functionType->getDescription();
     // check whether the type is already in the DB, if not insert it
     $query = new SelectQuery();
     $query->addTable("type");
     $query->addColumn("type_id", "id", "type");
     $query->addWhereEqual('type.type_domain', $domain);
     $query->addWhereEqual('type.type_authority', $authority);
     $query->addWhereEqual('type.type_keyword', $keyword);
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     if ($queryResult->getNumberOfRows() > 0) {
         // if the type is already in the database
         $functionTypeIdValue = $queryResult->field("id");
         // get the id
         $queryResult->free();
     } else {
         // if not, insert it
         $query = new InsertQuery();
         $query->setTable("type");
         $query->setAutoIncrementColumn("type_id", "type_type_id_seq");
         $query->addValue("type_domain", $domain);
         $query->addValue("type_authority", $authority);
         $query->addValue("type_keyword", $keyword);
         $query->addValue("type_description", $functionTypeDescription);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
         $functionTypeIdValue = $queryResult->getLastAutoIncrementValue();
     }
     // 2. Now that we know the id of the type, insert in the DB
     $query = new InsertQuery();
     $query->setTable("az_function");
     $query->addValue("function_id", $idValue);
     $query->addValue("function_reference_name", $displayName);
     $query->addValue("function_description", $description);
     $query->addValue("fk_qualifier_hierarchy", $qualifierHierarchyId->getIdString());
     $query->addValue("fk_type", $functionTypeIdValue);
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     if ($queryResult->getNumberOfRows() != 1) {
         $err = "Could not insert into database.";
         throwError(new Error($err, "authorizarion", true));
     }
     $this->_functions[$idValue] = $function;
     return $function;
 }
Exemplo n.º 14
0
 /**
  * Persistantly store a user preference
  * 
  * @param string $key
  * @param string $val
  * @return void
  * @access protected
  * @since 9/16/08
  */
 protected function _storePref($key, $val)
 {
     // Do not persist preferences for anonymous.
     if ($this->_getCurrentAgentId() == 'edu.middlebury.agents.anonymous') {
         return;
     }
     if ($this->_fetchPref($key) == $val) {
         return;
     }
     if (is_null($this->_fetchPref($key))) {
         $query = new InsertQuery();
         $query->addValue('agent_id', $this->_getCurrentAgentId());
         $query->addValue('pref_key', $key);
     } else {
         $query = new UpdateQuery();
         $query->addWhereEqual('agent_id', $this->_getCurrentAgentId());
         $query->addWhereEqual('pref_key', $key);
     }
     $query->setTable('user_prefs');
     $query->addValue('pref_val', $val);
     $dbc = Services::getService('DatabaseManager');
     try {
         $dbc->query($query);
     } catch (DuplicateKeyDatabaseException $e) {
         // If we have another window open that alreay changed the preference,
         // try again.
         unset($_SESSION['harmoni_user_prefs_persistant']);
         $this->_storePref($key, $val);
     }
     $_SESSION['harmoni_user_prefs_persistant'][$key] = $val;
 }
 /**
  * Store a mapping between Segue1 ids and Segue2 ids
  * 
  * @return void
  * @access protected
  * @since 3/20/08
  */
 protected function storeSegue1IdMapping()
 {
     if (!isset($this->origenSlotname)) {
         throw new OperationFailedException("Origen slot not set. Call " . get_class($this) . "->setOrigenSlotname('xxxxx').");
     }
     if (!isset($this->destSlotname)) {
         throw new OperationFailedException("Destination slot not set. Call " . get_class($this) . "->setDestinationSlotname('xxxxx').");
     }
     $dbc = Services::getService('DatabaseManager');
     $map = $this->filterNonAccessible($this->getIdMap());
     // 		printpre(htmlentities($this->doc->saveXMLWithWhitespace()));
     // 		printpre($map);
     // 		throw new Exception('test');
     // Delete any old mappings
     $query = new DeleteQuery();
     $query->setTable('segue1_id_map');
     $query->addWhereIn('segue1_id', array_keys($map));
     $dbc->query($query, IMPORTER_CONNECTION);
     // Add new mappings
     $query = new InsertQuery();
     $query->setTable('segue1_id_map');
     foreach ($map as $segue1Id => $segue2Id) {
         $query->createRow();
         $query->addValue('segue1_slot_name', $this->origenSlotname);
         $query->addValue('segue1_id', $segue1Id);
         $query->addValue('segue2_slot_name', $this->destSlotname);
         $query->addValue('segue2_id', $segue2Id);
     }
     $dbc->query($query, IMPORTER_CONNECTION);
 }
Exemplo n.º 16
0
 /**
  * Create a Hierarchy.
  * 
  * @param string $displayName
  * @param object Type[] $nodeTypes
  * @param string $description
  * @param boolean $allowsMultipleParents
  * @param boolean $allowsRecursion
  * @param optional object Id $id WARNING: NOT IN OSID
  *	
  * @return object Hierarchy
  * 
  * @throws object HierarchyException An exception with one of
  *		   the following messages defined in
  *		   org.osid.hierarchy.HierarchyException may be thrown:	 {@link
  *		   org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.hierarchy.HierarchyException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.hierarchy.HierarchyException#UNSUPPORTED_CREATION
  *		   UNSUPPORTED_CREATION}
  * 
  * @access public
  */
 function createHierarchy($displayName, array $nodeTypes, $description, $allowsMultipleParents, $allowsRecursion, Id $id = NULL)
 {
     // ** parameter validation
     ArgumentValidator::validate($description, StringValidatorRule::getRule(), true);
     ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
     ArgumentValidator::validate($allowsMultipleParents, BooleanValidatorRule::getRule(), true);
     ArgumentValidator::validate($allowsRecursion, BooleanValidatorRule::getRule(), true);
     ArgumentValidator::validate($id, OptionalRule::getRule(ExtendsValidatorRule::getRule("Id")), true);
     // ** end of parameter validation
     // check for supported hierarchies
     if ($allowsRecursion) {
         throw new OperationFailedException("Unsuported creation. Does not support recursion.");
     }
     $dbHandler = Services::getService("DatabaseManager");
     // Create an Id for the Hierarchy
     if (!is_object($id)) {
         $idManager = Services::getService("Id");
         $id = $idManager->createId();
     }
     $idValue = $id->getIdString();
     $query = new InsertQuery();
     $query->setTable("az2_hierarchy");
     $query->addValue("id", $idValue);
     $query->addValue("display_name", $displayName);
     $query->addValue("description", $description);
     $query->addValue("multiparent", $allowsMultipleParents ? '1' : '0');
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     // Create a new hierarchy and insert it into the database
     $cache = new AuthZ2_HierarchyCache($idValue, $allowsMultipleParents, $this->_dbIndex, isset($this->harmoni_db) ? $this->harmoni_db : null);
     $cache->setAuthorizationManager($this->getAuthorizationManager());
     $hierarchy = new AuthZ2_Hierarchy($id, $displayName, $description, $cache);
     // then cache it
     $this->_hierarchies[$idValue] = $hierarchy;
     return $hierarchy;
 }
Exemplo n.º 17
0
 /**
  * Set the contents of the file
  * 
  * @param string $contents
  * @return null
  * @access public
  * @since 5/15/08
  */
 public function setContents($contents)
 {
     try {
         $this->getContents();
         $query = new UpdateQuery();
         $query->addWhereEqual('fk_theme', $this->themeId);
         $query->addWhereEqual('path', $this->path);
     } catch (UnknownIdException $e) {
         $query = new InsertQuery();
         $query->addValue('fk_theme', $this->themeId);
         $query->addValue('path', $this->path);
         $mime = Services::getService("MIME");
         $query->addValue('mime_type', $mime->getMIMETypeForFileName($this->getBaseName()));
     }
     $query->setTable('segue_site_theme_image');
     $query->addValue('data', base64_encode($contents));
     $query->addValue('size', strlen($contents));
     $dbMgr = Services::getService("DatabaseManager");
     $result = $dbMgr->query($query, $this->databaseIndex);
     if (!$result->hasNext()) {
         throw new UnknownIdException("Theme image '" . $this->path . "' for theme '" . $this->themeId . "' does not exist.");
     }
     return $result->field('data');
 }
 /**
  * Add tokens to the system.
  * 
  * @param object AuthNTokens $authNTokens
  * @return void
  * @access public
  * @since 3/1/05
  */
 function addTokens($authNTokens)
 {
     /*********************************************************
      * Check validity
      *********************************************************/
     ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens"));
     if ($this->tokensExist($authNTokens)) {
         throw new OperationFailedException("Cannot create tokens: '" . $authNTokens->getUsername() . "' already exists.");
     }
     $email = $authNTokens->getUsername();
     // Check that the email is in a whitelisted domain if a whitelist is set.
     if (is_array($this->_configuration->getProperty('domain_whitelist'))) {
         $allowed = false;
         foreach ($this->_configuration->getProperty('domain_whitelist') as $domain) {
             if (preg_match('/' . str_replace('.', '\\.', $domain) . '$/i', $email)) {
                 $allowed = true;
                 break;
             }
         }
         if (!$allowed) {
             preg_match('/@([^@]+)$/', $email, $matches);
             throw new OperationFailedException("Cannot create visitor registrations from " . $matches[1] . ". Not in list of allowed domains.");
         }
     }
     // Check that the email is not in a blacklisted domain if a blacklist is set.
     if (is_array($this->_configuration->getProperty('domain_blacklist'))) {
         foreach ($this->_configuration->getProperty('domain_blacklist') as $domain) {
             if (preg_match('/' . str_replace('.', '\\.', $domain) . '$/i', $email)) {
                 throw new OperationFailedException("Cannot create visitor registration from {$domain}. Domain is black-listed.");
             }
         }
     }
     // Check that the email is not for someone with an account already in the
     // system through another authentication method.
     $methodMgr = Services::getService("AuthNMethodManager");
     $types = $methodMgr->getAuthNTypes();
     while ($types->hasNext()) {
         $method = $methodMgr->getAuthNMethodForType($types->next());
         $matching = $method->getTokensBySearch($email);
         while ($matching->hasNext()) {
             $properties = $method->getPropertiesForTokens($matching->next());
             if ($properties->getProperty('email') && strtolower($email) == strtolower($properties->getProperty('email'))) {
                 $message = dgettext("polyphony", "Cannot create visitor registration for %1. An account already exists in the %2 system. Please log in with your %2 username and password.");
                 $message = str_replace("%1", $email, $message);
                 $message = str_replace("%2", $method->getType()->getKeyword(), $message);
                 throw new OperationFailedException($message);
             }
         }
     }
     /*********************************************************
      * Add the tokens
      *********************************************************/
     $dbc = Services::getService("DatabaseManager");
     $dbId = $this->_configuration->getProperty('database_id');
     $authenticationTable = $this->_configuration->getProperty('authentication_table');
     $usernameField = $this->_configuration->getProperty('username_field');
     $passwordField = $this->_configuration->getProperty('password_field');
     $query = new InsertQuery();
     $query->setTable($authenticationTable);
     $query->addValue($usernameField, $authNTokens->getUsername());
     $query->addValue($passwordField, $authNTokens->getPassword());
     $query->addValue('display_name', $authNTokens->getUsername());
     $query->addValue('email_confirmed', '0');
     $query->addValue('confirmation_code', md5(rand()));
     $result = $dbc->query($query, $dbId);
     // Log the success
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Authentication");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
         $properties = $this->getPropertiesForTokens($authNTokens);
         $item = new AgentNodeEntryItem("Visitor Registration", "Visitor Registration entered: <br/>&nbsp;&nbsp;&nbsp;&nbsp;Email: " . htmlspecialchars($authNTokens->getIdentifier()) . " <br/>Still need to confirm email.");
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
 }
Exemplo n.º 19
0
 /**
  * Add a new image at the path specified.
  * 
  * @param object Harmoni_Filing_FileInterface $image
  * @param string $filename
  * @param string $prefixPath
  * @return null
  * @access public
  * @since 5/15/08
  */
 public function addImage(Harmoni_Filing_FileInterface $image, $filename, $prefixPath = '')
 {
     if (!$this->canModify()) {
         throw new PermissionDeniedException();
     }
     ArgumentValidator::validate($filename, NonzeroLengthStringValidatorRule::getRule());
     $path = trim($prefixPath, '/');
     if (strlen($path)) {
         $path = $path . '/' . $filename;
     } else {
         $path = $filename;
     }
     // Delete the old image
     $query = new DeleteQuery();
     $query->setTable('segue_site_theme_image');
     $query->addWhereEqual('fk_theme', $this->id);
     $query->addWhereEqual('path', $path);
     $dbc = Services::getService('DatabaseManager');
     $dbc->query($query, $this->databaseIndex);
     $query = new InsertQuery();
     $query->setTable('segue_site_theme_image');
     $query->addValue('fk_theme', $this->id);
     $query->addValue('mime_type', $image->getMimeType());
     $query->addValue('path', $path);
     $query->addValue('size', $image->getSize());
     $query->addValue('data', base64_encode($image->getContents()));
     $dbc = Services::getService('DatabaseManager');
     $dbc->query($query, $this->databaseIndex);
 }
Exemplo n.º 20
0
 /**
  * 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);
     }
 }