Exemplo n.º 1
0
 public function findFiles(array $terms, &$total_count, $start = 0, $limit = -1, array $sort_flds = array(), $get_cb = array('RODSConnManager', 'getConn'), $rel_cb = array('RODSConnManager', 'releaseConn'))
 {
     $flds = array("COL_DATA_NAME" => NULL, "COL_D_DATA_ID" => NULL, "COL_DATA_TYPE_NAME" => NULL, "COL_D_RESC_NAME" => NULL, "COL_DATA_SIZE" => NULL, "COL_D_OWNER_NAME" => NULL, "COL_D_OWNER_ZONE" => NULL, "COL_D_CREATE_TIME" => NULL, "COL_D_MODIFY_TIME" => NULL, "COL_COLL_NAME" => NULL, "COL_D_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_DATA_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'size':
                 if ($sort_fld_val === false) {
                     $flds['COL_DATA_SIZE'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_SIZE'] = 'order_by_asc';
                 }
                 break;
             case 'mtime':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_MODIFY_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_MODIFY_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'ctime':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_CREATE_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_CREATE_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'typename':
                 if ($sort_fld_val === false) {
                     $flds['COL_DATA_TYPE_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_TYPE_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'owner':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_OWNER_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_OWNER_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'dirname':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_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;
     $logicalFile = false;
     $condition = new RODSGenQueConds();
     foreach ($terms as $term_key => $term_val) {
         switch ($term_key) {
             case 'name':
                 //$condition->add('COL_DATA_NAME', 'like', '%'.$term_val.'%');
                 $condition->add('COL_DATA_NAME', 'like', $term_val);
                 break;
             case 'smtime':
                 $condition->add('COL_D_MODIFY_TIME', '>=', $term_val);
                 break;
             case 'emtime':
                 $condition->add('COL_D_MODIFY_TIME', '<', $term_val);
                 break;
             case 'owner':
                 $condition->add('COL_D_OWNER_NAME', '=', $term_val);
                 break;
             case 'ownerzone':
                 $condition->add('COL_D_OWNER_ZONE', '=', $term_val);
                 break;
             case 'rescname':
                 $condition->add('COL_D_RESC_NAME', '=', $term_val);
                 break;
             case 'metadata':
                 $meta_array = $term_val;
                 foreach ($meta_array as $meta) {
                     if (isset($meta->name)) {
                         if ($meta->nameop === 'like') {
                             $condition->add('COL_META_DATA_ATTR_NAME', 'like', '%' . $meta->name . '%');
                         } else {
                             if (isset($meta->nameop)) {
                                 $condition->add('COL_META_DATA_ATTR_NAME', $meta->nameop, $meta->name);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_NAME', '=', $meta->name);
                             }
                         }
                     }
                     if (isset($meta->value)) {
                         if ($meta->op === 'like') {
                             $condition->add('COL_META_DATA_ATTR_VALUE', 'like', '%' . $meta->value . '%');
                         } else {
                             if (isset($meta->op)) {
                                 $condition->add('COL_META_DATA_ATTR_VALUE', $meta->op, $meta->value);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_VALUE', '=', $meta->value);
                             }
                         }
                     }
                     if (isset($meta->unit)) {
                         if ($meta->unitop === 'like') {
                             $condition->add('COL_META_DATA_ATTR_UNIT', 'like', '%' . $meta->unit . '%');
                         } else {
                             if (isset($meta->unitop)) {
                                 $condition->add('COL_META_DATA_ATTR_UNIT', $meta->unitop, $meta->unit);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_UNIT', '=', $meta->unit);
                             }
                         }
                     }
                 }
                 break;
             case 'descendantOnly':
                 if (true === $term_val) {
                     $descendantOnly = true;
                 }
                 break;
             case 'recursive':
                 if (true === $term_val) {
                     $recursive = true;
                 }
                 break;
             case 'logicalFile':
                 if (true === $term_val) {
                     $logicalFile = true;
                 }
                 break;
             default:
                 throw new RODSException("Term field name '{$term_key}' is not valid", 'PERR_USER_INPUT_ERROR');
                 break;
         }
     }
     if ($descendantOnly === true) {
         if ($recursive === true) {
             $condition->add('COL_COLL_NAME', 'like', $this->path_str . '/%', array(array('op' => '=', 'val' => $this->path_str)));
         } else {
             $condition->add('COL_COLL_NAME', '=', $this->path_str);
         }
     }
     if ($logicalFile === true) {
         $select->update('COL_D_RESC_NAME', 'count');
         $select->update('COL_DATA_SIZE', 'max');
         $select->update('COL_D_CREATE_TIME', 'min');
         $select->update('COL_D_MODIFY_TIME', 'max');
     }
     //$conn = RODSConnManager::getConn($this->account);
     $conn = call_user_func_array($get_cb, array(&$this->account));
     $results = $conn->query($select, $condition, $start, $limit);
     //RODSConnManager::releaseConn($conn);
     call_user_func($rel_cb, $conn);
     $total_count = $results->getTotalCount();
     $result_values = $results->getValues();
     $found = array();
     for ($i = 0; $i < $results->getNumRow(); $i++) {
         $resc_name = $logicalFile === true ? NULL : $result_values['COL_D_RESC_NAME'][$i];
         $num_replica = $logicalFile === true ? intval($result_values['COL_D_RESC_NAME'][$i]) : NULL;
         $stats = new RODSFileStats($result_values['COL_DATA_NAME'][$i], $result_values['COL_DATA_SIZE'][$i], $result_values['COL_D_OWNER_NAME'][$i], $result_values['COL_D_OWNER_ZONE'][$i], $result_values['COL_D_MODIFY_TIME'][$i], $result_values['COL_D_CREATE_TIME'][$i], $result_values['COL_D_DATA_ID'][$i], $result_values['COL_DATA_TYPE_NAME'][$i], $resc_name, $result_values['COL_D_COMMENTS'][$i], $num_replica);
         if ($result_values['COL_COLL_NAME'][$i] == '/') {
             $full_path = '/' . $result_values['COL_DATA_NAME'][$i];
         } else {
             $full_path = $result_values['COL_COLL_NAME'][$i] . '/' . $result_values['COL_DATA_NAME'][$i];
         }
         $found[] = new ProdsFile($this->account, $full_path, false, $stats);
     }
     return $found;
 }