public function deleteQueue() { return $this->backend->deleteQueue(); }
/** * * @param drealtyConnectionEntity $connection * @param drealtyRetsResource $resource * @param drealtyRetsClass $class * @param string $entity_type * @param int $chunk_count */ protected function process_results(drealtyConnectionEntity $connection, $resource, $class, $entity_type) { global $user; $in_rets = array(); $key_field = 'rets_key'; $existing_items = db_select($entity_type, "t")->fields("t", array($key_field, "hash", "id"))->condition("conid", $connection->conid)->condition('class', $class->cid)->execute()->fetchAllAssoc($key_field); // get the fieldmappings $field_mappings = $connection->FetchFieldMappings($resource, $class); // set $id to the systemname of the entity's corresponding key from the rets feed to make the code easier to read $id = $field_mappings[$key_field]->systemname; $item_context = array('field_mappings' => $field_mappings, 'connection' => $connection, 'resource' => $resource, 'key_field' => $key_field); $total = $this->queue->numberOfItems(); $count = 1; while ($queue_item = $this->queue->claimItem()) { $rets_item = $queue_item->data; $in_rets[$rets_item[$id]] = $rets_item[$id]; $force = FALSE; if (!empty($connection->nomap_mode)) { // This connection does not use field mappings, just remove the item // from the queue and handle expired listings. drush_log(dt("Got item @name. [@count of @total]", array("@name" => $rets_item[$id], "@count" => $count, "@total" => $total))); $this->queue->deleteItem($queue_item); } else { if (!isset($existing_items[$rets_item[$id]]) || $existing_items[$rets_item[$id]]->hash != $rets_item['hash'] || $force) { // Allow other modules to preprocess RETS fields before mapping them. drupal_alter('drealty_import_rets_item', $rets_item, $item_context); // this listing either doesn't exist in the IDX or has changed. // determine if we need to update or create a new one. if (isset($existing_items[$rets_item[$id]])) { // this listing exists so we'll get a reference to it and set the values to what came to us in the RETS result $entities = array($existing_items[$rets_item[$id]]->id); $item = reset(entity_load($entity_type, $entities)); $is_new = FALSE; } else { $item = entity_create($entity_type, array('conid' => $connection->conid, 'type' => $class->bundle)); $is_new = TRUE; $item->created = time(); } $item->conid = $connection->conid; $item->hash = $rets_item['hash']; $item->changed = time(); $item->class = $class->cid; $item->rets_imported = TRUE; $item->uid = $user->uid; $item->active = 1; $item->inactive_date = NULL; // set the title to the rets_id initially, then it can be changed in hook_presave() if needed. $item->label = $rets_item[$field_mappings['rets_id']->systemname]; if ($entity_type == 'drealty_listing' && $class->process_images) { if ($is_new) { $item->process_images = TRUE; $item->rets_photo_modification_timestamp = $rets_item[$class->photo_timestamp_field]; } else { if (isset($item->rets_photo_modification_timestamp)) { $last_time = strtotime($item->rets_photo_modification_timestamp); $this_time = strtotime($rets_item[$class->photo_timestamp_field]); if ($this_time > $last_time) { $item->process_images = TRUE; $item->rets_photo_modification_timestamp = $rets_item[$class->photo_timestamp_field]; } else { $item->process_images = FALSE; } } else { // hasn't been set but it's not new $item->rets_photo_modification_timestamp = $rets_item[$class->photo_timestamp_field]; $item->process_images = FALSE; } } } $this->set_field_data($item, $rets_item, $field_mappings, $entity_type, $class); $item_context['rets_item'] = $rets_item; try { drupal_alter('drealty_import_presave', $item, $item_context); $item->save(); module_invoke_all('drealty_entity_save', array(&$item, $item_context)); $this->queue->deleteItem($queue_item); } catch (Exception $e) { drush_log($e->getMessage()); $this->queue->releaseItem($queue_item); } drush_log(dt('Saving item @name. [@count of @total]', array("@name" => $item->label, "@count" => $count, "@total" => $total))); unset($item); } else { // skipping this item drush_log(dt("Skipping item @name. [@count of @total]", array("@name" => $rets_item[$id], "@count" => $count, "@total" => $total))); $this->queue->deleteItem($queue_item); } } $count++; drupal_get_messages(); drupal_static_reset(); } //handle expired listings if (count($in_rets)) { $this->handle_expired($in_rets, $connection->conid, $class); } }