Exemplo n.º 1
0
 function __perform_refresh_cache_batch()
 {
     if ($this->_batchlimit > 0) {
         $results = fetch_file_cache_refresh_rs('ITEM');
         if ($results) {
             while ($file_cache_r = db_fetch_assoc($results)) {
                 // in this case we want to refresh the URL, so TRUE as last parameter idicates overwrite
                 if (file_cache_insert_file($file_cache_r['url'], NULL, NULL, NULL, 'ITEM', TRUE)) {
                     $this->_processed++;
                 } else {
                     $this->_failures++;
                 }
                 // don't process anymore this time around.
                 if ($this->_processed >= $this->_batchlimit) {
                     break;
                 }
             }
             db_free_result($results);
         }
     }
     $this->_remaining = fetch_file_cache_refresh_cnt('ITEM');
 }
Exemplo n.º 2
0
 function &fetchURI($URI, $http_cache = TRUE)
 {
     @set_time_limit(600);
     $URI = trim($URI);
     $this->__debug('fetchURI', "URI: {$URI}");
     $this->_file_cache_r = NULL;
     $overwrite_cache_entry = FALSE;
     if ($http_cache !== FALSE && $this->_file_cache_enabled) {
         // see if we can find the cache file.
         $this->_file_cache_r = fetch_url_file_cache_r($URI, 'HTTP');
         if ($this->_file_cache_r !== FALSE) {
             $file_location = file_cache_get_cache_file($this->_file_cache_r);
             if ($file_location !== FALSE) {
                 $this->_file_cache_r['content'] = file_get_contents($file_location);
                 if (strlen($this->_file_cache_r['content']) == 0) {
                     $this->__debug('fetchURI', 'URL cache invalid');
                     $overwrite_cache_entry = TRUE;
                     unset($this->_file_cache_r);
                 }
             } else {
                 unset($this->_file_cache_r);
             }
         }
     }
     if (is_not_empty_array($this->_file_cache_r)) {
         $this->__debug('fetchURI', 'URL cached');
         return $this->_file_cache_r['content'];
     } else {
         $this->__debug('fetchURI', 'URL NOT cached');
         if ($this->fetch($URI) && $this->status >= 200 && $this->status < 300) {
             opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, NULL, array($URI));
             $this->_file_cache_r['url'] = $URI;
             $this->_file_cache_r['content'] = $this->results;
             $this->results = NULL;
             if (strlen($this->_file_cache_r['content']) > 0) {
                 $this->__debug('fetchURI', 'URL fetched (Size=' . strlen($this->_file_cache_r['content']) . ')');
                 // assume a default.
                 $this->_file_cache_r['content_type'] = 'text/html';
                 if (is_array($this->headers) && count($this->headers) > 0) {
                     for ($i = 0; $i < count($this->headers); $i++) {
                         if (preg_match("/^([^:]*):([^\$]*)\$/i", $this->headers[$i], $matches)) {
                             if (strcasecmp(trim($matches[1]), 'content-type') === 0) {
                                 $this->_file_cache_r['content_type'] = trim($matches[2]);
                                 break;
                             }
                         }
                     }
                 }
                 $this->_file_cache_r['location'] = $this->lastredirectaddr;
                 if ($http_cache !== FALSE && $this->_file_cache_enabled) {
                     if (file_cache_insert_file($this->_file_cache_r['url'], $this->_file_cache_r['location'], $this->_file_cache_r['content_type'], $this->_file_cache_r['content'], 'HTTP', $overwrite_cache_entry) !== FALSE) {
                         $this->__debug('fetchURI', "Added {$URI} to file cache");
                     } else {
                         $this->__debug('fetchURI', "Failed to add {$URI} to file cache");
                     }
                 }
                 //if($http_cache!==FALSE && $this->_file_cache_enabled)
             }
             //if(strlen($_file_cache_r['content'])>0)
             return $this->_file_cache_r['content'];
         } else {
             $this->__debug('fetchURI', "Failed to fetch {$URI}", ifempty($this->error, 'Status ' . $this->status));
             opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, ifempty($this->error, 'Status ' . $this->status), array($URI));
             return FALSE;
         }
     }
 }
Exemplo n.º 3
0
/**
*/
function _insert_or_update_item_attributes($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r = NULL)
{
    $is_lookup_attribute_type = is_lookup_attribute_type($s_attribute_type);
    $attribute_val_r = validate_attribute_val_r($attribute_val_r, $is_lookup_attribute_type);
    // if not instance item attribute, then discard the $instance_no
    if (!is_instance_item_attribute_type($s_item_type, $s_attribute_type)) {
        $instance_no = NULL;
    }
    $is_file_resource_attribute_type = is_file_resource_attribute_type($s_attribute_type);
    if (db_query("LOCK TABLES item_attribute WRITE, item_attribute AS ia READ, s_attribute_type AS sat READ")) {
        $item_attribute_type_rs = fetch_arrayof_item_attribute_rs($item_id, $instance_no, $s_attribute_type, $order_no);
        // if same number of attributes, then we can perform an update only.
        if (count($item_attribute_type_rs) > 0 && count($item_attribute_type_rs) == count($attribute_val_r)) {
            $op = 'update';
        } else {
            if (count($item_attribute_type_rs) == 0 || delete_item_attributes($item_id, $instance_no, $s_attribute_type, $order_no)) {
                $op = 'insert';
            } else {
                // if this occurs then the delete_item_attributes function returned FALSE, and that failure would have been logged.
                db_query("UNLOCK TABLES");
                return FALSE;
            }
        }
        // if there is actually something to insert at this point.
        if (count($attribute_val_r) > 0) {
            $file_attributes_r = NULL;
            for ($i = 0; $i < count($attribute_val_r); $i++) {
                $attribute_no = $i + 1;
                if ($is_lookup_attribute_type) {
                    if ($op == 'insert') {
                        insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL);
                    } else {
                        if ($item_attribute_type_rs[$i]['lookup_attribute_val'] != $attribute_val_r[$i]) {
                            update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL);
                        }
                    }
                } else {
                    if ($is_file_resource_attribute_type) {
                        if (is_array($file_r) && is_uploaded_file($file_r['tmp_name'])) {
                            if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i] && is_exists_upload_file_item_attribute($attribute_val_r[$i])) {
                                $attribute_val_r[$i] = get_unique_filename($attribute_val_r[$i]);
                            }
                            if (!save_uploaded_file($file_r['tmp_name'], $attribute_val_r[$i])) {
                                $attribute_val_r[$i] = NULL;
                            }
                            $file_attributes_rs[] = array('file_attribute_ind' => 'Y', 'attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]);
                        } else {
                            $file_attributes_rs[] = array('attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]);
                        }
                    }
                    if (strlen($attribute_val_r[$i]) > 0) {
                        if ($op == 'insert') {
                            insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]);
                        } else {
                            if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i]) {
                                update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]);
                            }
                        }
                    }
                }
            }
            db_query("UNLOCK TABLES");
            if (is_array($file_attributes_rs)) {
                while (list(, $file_attribute_r) = each($file_attributes_rs)) {
                    file_cache_insert_file($file_attribute_r['attribute_val'], NULL, NULL, NULL, 'ITEM', $file_attribute_r['file_attribute_ind'] == 'Y');
                }
            }
        } else {
            db_query("UNLOCK TABLES");
        }
        return TRUE;
    } else {
        opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r));
        return FALSE;
    }
}