Example #1
0
 /**
  * Set multiple metadata values using database columns as indexes.
  *
  * @param array $p_md
  *  example: $p_md['url'] = 'http://www.fake.com'
  */
 public function setDbColMetadata($p_md = null)
 {
     if (is_null($p_md)) {
         foreach ($this->_dbMD as $dbColumn => $propelColumn) {
             $method = "set{$propelColumn}";
             $this->_file->{$method}(null);
         }
     } else {
         $owner = $this->_file->getFkOwner();
         // if owner_id is already set we don't want to set it again.
         if (!$owner) {
             // no owner detected, we try to assign one.
             // if MDATA_OWNER_ID is not set then we default to the
             // first admin user we find
             if (!array_key_exists('owner_id', $p_md)) {
                 //$admins = Application_Model_User::getUsers(array('A'));
                 $admins = Application_Model_User::getUsersOfType('A');
                 if (count($admins) > 0) {
                     // found admin => pick first one
                     $owner = $admins[0];
                 }
             } else {
                 $user = CcSubjsQuery::create()->findPk($p_md['owner_id']);
                 if ($user) {
                     $owner = $user;
                 }
             }
             if ($owner) {
                 $this->_file->setDbOwnerId($owner->getDbId());
             } else {
                 Logging::info("Could not find suitable owner for file\n                        '" . $p_md['MDATA_KEY_FILEPATH'] . "'");
             }
         }
         # We don't want to process owner_id in bulk because we already
         # processed it in the code above. This is done because owner_id
         # needs special handling
         if (array_key_exists('owner_id', $p_md)) {
             unset($p_md['owner_id']);
         }
         foreach ($p_md as $dbColumn => $mdValue) {
             // don't blank out name, defaults to original filename on first
             // insertion to database.
             if ($dbColumn == "track_title" && (is_null($mdValue) || $mdValue == "")) {
                 continue;
             }
             # TODO : refactor string evals
             if (isset($this->_dbMD[$dbColumn])) {
                 $propelColumn = $this->_dbMD[$dbColumn];
                 $method = "set{$propelColumn}";
                 /* We need to set track_number to null if it is an empty string
                  * because propel defaults empty strings to zeros */
                 if ($dbColumn == "track_number" && empty($mdValue)) {
                     $mdValue = null;
                 }
                 $this->_file->{$method}($mdValue);
             }
         }
     }
     $this->_file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
     $this->_file->save();
 }
Example #2
0
 public static function getFirstAdmin()
 {
     $admins = Application_Model_User::getUsersOfType('A');
     if (count($admins) > 0) {
         // found admin => pick first one
         return $admins[0];
     } else {
         Logging::warn("Warning. no admins found in database");
         return null;
     }
 }