/**
  * Get all user defined metadata names for all directories(collections) on the server.
  * @return array of strings (metadata names).
  */
 public function getMetadataNamesForAllDirs()
 {
     $flds = array("COL_META_COLL_ATTR_NAME" => NULL);
     $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
     $condition = new RODSGenQueConds();
     $condition->add('COL_COLL_ID', '>=', '0');
     $conn = RODSConnManager::getConn($this->account);
     $results = $conn->query($select, $condition);
     RODSConnManager::releaseConn($conn);
     if ($results->getNumRow() < 1) {
         return array();
     } else {
         $values = $results->getValues();
         return $values['COL_META_COLL_ATTR_NAME'];
     }
 }
 /**
  * Makes a general query to RODS server. Think it as an SQL. "select foo from sometab where bar = '3'". In this example, foo is specified by "$select", bar and "= '3'" are speficed by condition.
  * @param RODSGenQueSelFlds $select the fields (names) to be returned/interested. There can not be more than 50 input fields. For example:"COL_COLL_NAME" means collection-name.
  * @param RODSGenQueConds $condition  All fields are defined in RodsGenQueryNum.inc.php and RodsGenQueryKeyWd.inc.php
  * @param integer $start result start from which row.
  * @param integer $limit up to how many rows should the result contain. If -1 is passed, all available rows will be returned
  * @return RODSGenQueResults
  * Note: This function is very low level. It's not recommended for beginners.
  */
 public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $start = 0, $limit = -1)
 {
     if ($select->getCount() < 1 || $select->getCount() > 50) {
         throw new RODSException("Only 1-50 fields are supported", 'PERR_USER_INPUT_ERROR');
     }
     // contruct select packet (RP_InxIvalPair $selectInp), and condition packets
     $select_pk = $select->packetize();
     $cond_pk = $condition->packetize();
     $condkw_pk = $condition->packetizeKW();
     // determin max number of results per query
     if ($limit > 0 && $limit < 500) {
         $max_result_per_query = $limit;
     } else {
         $max_result_per_query = 500;
     }
     $num_fetched_rows = 0;
     $continueInx = 0;
     $results = new RODSGenQueResults();
     do {
         // construct RP_GenQueryInp packet
         $options = 1 | $GLOBALS['PRODS_GENQUE_NUMS']['RETURN_TOTAL_ROW_COUNT'];
         $genque_input_pk = new RP_GenQueryInp($max_result_per_query, $continueInx, $condkw_pk, $select_pk, $cond_pk, $options, $start);
         // contruce a new API request message, with type GEN_QUERY_AN
         $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']);
         fwrite($this->conn, $msg->pack());
         // send it
         // get value back
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') {
                 break;
             }
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
         $genque_result_pk = $msg_resv->getBody();
         $num_row_added = $results->addResults($genque_result_pk);
         $continueInx = $genque_result_pk->continueInx;
         $start = $start + $results->getNumRow();
     } while ($continueInx > 0 && ($results->getNumRow() < $limit || $limit < 0));
     // Make sure and close the query if there are any results left.
     if ($continueInx > 0) {
         $msg->getBody()->continueInx = $continueInx;
         $msg->getBody()->maxRows = -1;
         // tells the server to close the query
         fwrite($this->conn, $msg->pack());
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
     }
     return $results;
 }
Example #3
0
 /**
  * query metadata, and find matching diretories.
  * @param array $terms an assositive array of search conditions, supported ones are:
  * -    'name' (string) - partial name of the target (file or dir)
  * -    'descendantOnly' (boolean) - whether to search among this directory's decendents. default is false.
  * -    'recursive'      (boolean) - whether to search recursively, among all decendents and their children. default is false. This option only works when 'descendantOnly' is true
  * -    'smtime'         (int)     - start last-modified-time in unix timestamp. The specified time is included in query, in other words the search can be thought was "mtime >= specified time"
  * -    'emtime'         (int)     - end last-modified-time in unix timestamp. The specified time is not included in query, in other words the search can be thought was "mtime < specified time"
  * -    'owner'          (string)  - owner name of the dir
  * -    'metadata' (array of RODSMeta) - array of metadata.
  * @param int &$total_count This value (passed by reference) returns the total potential count of search results
  * @param int $start starting index of search results.
  * @param int $limit up to how many results to be returned. If negative, give all results back.
  * @param array $sort_flds associative array with following keys:
  * -     'name'      - name of the dir
  * -     'mtime'     - last modified time
  * -     'ctime'     - creation time
  * -     'owner'     - owner of the dir
  * The results are sorted by specified array keys.
  * The possible array value must be boolean: true stands for 'asc' and false stands for 'desc', default is 'asc'
  * @return array of ProdsPath objects (ProdsFile or ProdsDir).
  */
 public function findDirs(array $terms, &$total_count, $start = 0, $limit = -1, array $sort_flds = array())
 {
     $flds = array("COL_COLL_NAME" => NULL, "COL_COLL_ID" => NULL, "COL_COLL_OWNER_NAME" => NULL, 'COL_COLL_OWNER_ZONE' => NULL, "COL_COLL_CREATE_TIME" => NULL, "COL_COLL_MODIFY_TIME" => NULL, "COL_COLL_COMMENTS" => NULL);
     foreach ($sort_flds as $sort_fld_key => $sort_fld_val) {
         switch ($sort_fld_key) {
             case 'name':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'mtime':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_MODIFY_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_MODIFY_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'ctime':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_CREATE_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_CREATE_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'owner':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_OWNER_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_OWNER_NAME'] = 'order_by_asc';
                 }
                 break;
             default:
                 /*
                 throw new RODSException("Sort field name '$sort_fld_key' is not valid",
                   'PERR_USER_INPUT_ERROR');
                 */
                 break;
         }
     }
     $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
     $descendantOnly = false;
     $recursive = false;
     $condition = new RODSGenQueConds();
     foreach ($terms as $term_key => $term_val) {
         switch ($term_key) {
             case 'name':
                 //$condition->add('COL_COLL_NAME', 'like', '%'.$term_val.'%');
                 $condition->add('COL_COLL_NAME', 'like', $term_val);
                 break;
             case 'smtime':
                 $condition->add('COL_COLL_MODIFY_TIME', '>=', $term_val);
                 break;
             case 'emtime':
                 $condition->add('COL_COLL_MODIFY_TIME', '<', $term_val);
                 break;
             case 'owner':
                 $condition->add('COL_COLL_OWNER_NAME', '=', $term_val);
                 break;
             case 'metadata':
                 $meta_array = $term_val;
                 foreach ($meta_array as $meta) {
                     $condition->add('COL_META_COLL_ATTR_NAME', '=', $meta->name);
                     if (isset($meta->op)) {
                         $op = $meta->op;
                     } else {
                         $op = '=';
                     }
                     if ($op == 'like') {
                         //$value='%'.$meta->value.'%';
                         $value = $meta->value;
                     } else {
                         $value = $meta->value;
                     }
                     $condition->add('COL_META_COLL_ATTR_VALUE', $op, $value);
                 }
                 break;
             case 'descendantOnly':
                 if (true === $term_val) {
                     $descendantOnly = true;
                 }
                 break;
             case 'recursive':
                 if (true === $term_val) {
                     $recursive = true;
                 }
                 break;
             default:
                 throw new RODSException("Term field name '{$term_key}' is not valid", 'PERR_USER_INPUT_ERROR');
                 break;
         }
     }
     if ($descendantOnly === true) {
         // eliminate '/' from children, if current path is already root
         if ($this->path_str == '/') {
             $condition->add('COL_COLL_NAME', '<>', '/');
         }
         if ($recursive === true) {
             $condition->add('COL_COLL_PARENT_NAME', 'like', $this->path_str . '/%', array(array('op' => '=', 'val' => $this->path_str)));
         } else {
             $condition->add('COL_COLL_PARENT_NAME', '=', $this->path_str);
         }
     }
     $conn = RODSConnManager::getConn($this->account);
     $results = $conn->query($select, $condition, $start, $limit);
     RODSConnManager::releaseConn($conn);
     $total_count = $results->getTotalCount();
     $result_values = $results->getValues();
     $found = array();
     for ($i = 0; $i < $results->getNumRow(); $i++) {
         $full_path = $result_values['COL_COLL_NAME'][$i];
         $acctual_name = basename($result_values['COL_COLL_NAME'][$i]);
         $stats = new RODSDirStats($acctual_name, $result_values['COL_COLL_OWNER_NAME'][$i], $result_values['COL_COLL_OWNER_ZONE'][$i], $result_values['COL_COLL_MODIFY_TIME'][$i], $result_values['COL_COLL_CREATE_TIME'][$i], $result_values['COL_COLL_ID'][$i], $result_values['COL_COLL_COMMENTS'][$i]);
         $found[] = new ProdsDir($this->account, $full_path, false, $stats);
     }
     return $found;
 }