public function save($chain_name) { $domain_name = $this->_domain_name; $item_name = $chain_name; $attributes = SimpleDbUtils::genSimpleDbAttributesArray(array("chain_name" => $chain_name)); SimpleDbPersister::save($domain_name, $item_name, $attributes); }
public function import() { ini_set("auto_detect_line_endings", true); $domain_name = $this->_domain_name; $file_name = $this->csv_file_path; $file_handle = fopen($file_name, "r"); /** * id,area_name,pincode */ $line_number = 0; $header_line = null; $buffered_record_count = 0; $buffered_records = array(); while (($line = fgetcsv($file_handle, $file_name)) !== FALSE) { $line_number++; //Skip first line as they are the column headers in excel sheet if ($line_number == 1) { $header_line = $line; continue; } $id = $line[0]; $category = $line[1]; $category = trim($category, '"'); $attributes = array($header_line[0] => $id, $header_line[1] => $category); $simpledb_record = array("name" => $id, "attributes" => $attributes); //SimpleDb can save a maximum of 25 records in a batch if ($buffered_record_count < 25) { $buffered_record_count++; array_push($buffered_records, $simpledb_record); } else { $items = SimpleDbUtils::genSimpleDbMultipleItemsArray($buffered_records); SimpleDbPersister::batch_save($domain_name, $items); $buffered_records = array(); $buffered_record_count = 0; } } //Upload remaining buffered records if ($buffered_record_count > 0) { $items = SimpleDbUtils::genSimpleDbMultipleItemsArray($buffered_records); SimpleDbPersister::batch_save($domain_name, $items); } }
return; } //If a new business entry, check whether it exists already if ($is_update_operation === FALSE && CoreAttributesUtils::exists($data) === TRUE) { $error_json = array("status" => "error", "error" => "Business already exists"); echo json_encode($error_json); return; } //If an update operation, don't re-generate business_id and set $replace to true if ($is_update_operation === TRUE) { $attributes = SimpleDbUtils::genSimpleDbAttributesArray($data, true); } else { $is_busines_id_already_taken = false; /* Check whether the unique business id that is generated is already not * taken. */ do { $business_id = BusinessIdGenerator::generate($data["pincode"]); $data["business_id"] = $business_id; $result = SimpleDbPersister::getAttributes($domain_name, $business_id, array("business_id")); $is_business_id_already_taken = empty($result) ? false : true; } while ($is_business_id_already_taken === TRUE); $attributes = SimpleDbUtils::genSimpleDbAttributesArray($data); } $message = CoreAttributesUtils::generateSMSMessage($data); SMS::send($sms_number, $message); $business_id = $data["business_id"]; SimpleDbPersister::save($domain_name, $business_id, $attributes); $success_json = array("status" => "success", "business_id" => $business_id, "created_by_user" => $data["created_by_user"], "created_time" => $data["created_time"]); echo json_encode($success_json); return;
} //TODO: Clean this code if (isset($data["business_specific_attributes"]) === TRUE) { $keys = array_keys($data["business_specific_attributes"]); $business_specific_attributes = array(); foreach ($data["business_specific_attributes"] as $key => $value) { $business_specific_attributes[$key] = $value; } unset($data["business_specific_attributes"]); $data = array_merge($data, $business_specific_attributes); } /* Encoding it as JSON because hours_of_operation should be saved as a JSON * in SimpleDb. */ $data["hours_of_operation"] = json_encode($data["hours_of_operation"]); $data["status"] = "BUSINESS_VERIFIED_COMPLETE"; $attributes = SimpleDbUtils::genSimpleDbAttributesArray($data, TRUE); SimpleDbPersister::save($domain_name, $business_id, $attributes); $success_json = array("status" => "success", "last_updated_time" => $last_updated_time); echo json_encode($success_json); fastcgi_finish_request(); //Backing up old data $attributes = SimpleDbUtils::genSimpleDbAttributesArray($business_details, TRUE); SimpleDbPersister::save($backup_domain_name, $business_id, $attributes); //Delete old S3 Photos if (empty($photo_url_array) === TRUE) { return; } $new_photo_url_array = $data["photo_url"]; S3PhotoDeleter::delete($photo_url_array, $new_photo_url_array); return;