I need to edit some PHP that wasn't written by me, I've gotten most of it done but there's a bit I can't figure out the correct syntax for.
Basically we grab data from a Google Fusion Table and populate a table with it, once we've edited the data in the table we can update that information to a production version of the same table. One of the update queries looks like this:
if($table_row[12]=="New"){
$tableid1 = '1bsSleKDBdkhQZfn-oADx0tUtoOc32RqIyiX05Bo';
$insertresults = $ftclient->query(SQLBuilder::insert($tableid1,
array('SUBURB'=> $table_row[1],
'ROAD_NAME' => $table_row[2],
'DESCRIPTION' => $table_row[3],
'DIRECTION' => $table_row[4],
'STATUS' => $table_row[5],
'SITE_ID' => $table_row[6],
'COMMON_NAME' => $table_row[7],
'Lat' => $table_row[8],
'Long' => $table_row[9],
'OPERATING_DAY' => $table_row[10],
'OPERATING_HOURS' => $table_row[11],
'Version' => "current")));
$insertresults = explode("\n", $insertresults);
$rowid1 = $insertresults[1];
$updateresults = $ftclient->query(SQLBuilder::update($tableid,
array('SUBURB'=> $table_row[1],
'ROAD_NAME' => $table_row[2],
'DESCRIPTION' => $table_row[3],
'DIRECTION' => $table_row[4],
'STATUS' => $table_row[5],
'SITE_ID' => $table_row[6],
'COMMON_NAME' => $table_row[7],
'Lat' => $table_row[8],
'Long' => $table_row[9],
'OPERATING_DAY' => $table_row[10],
'OPERATING_HOURS' => $table_row[11],
'Version' => "current",
'Edited_By' => $table_row[13],
'Date_Edited' => $table_row[14]),$table_row[0]));
$updateresults = explode("\n", $updateresults);
$rowid2 = $updateresults[1];
}
What I need to do is write a similar type of SQLBuilder query that will update every record with the same SITE_ID when SUBURB is changed in one of them (i.e., if a record has SUBURB Sydney, SITE_ID 1, each record with SITE_ID 1 must be changed if one record's SUBURB value is changed from Sydney to Melbourne). Not sure exactly how to phrase this syntactically or how I would go about writing the query using SQLBuilder. Any helpw would be appreciated!
SQLBuilder is obviously a locally included class. You will need to look at its documentation or the update method itself in order to see how it expects a where clause to be coded.
The SQL for this would be:
"UPDATE tableid SET SUBURB = '{$table_row[1]}' WHERE SITE_ID = '{$table_row[6]}'"
If you are able to run pure SQL then that will do it. Otherwise I'd need to see the Class libraries.
Related
Could someone please provide a simple example of the usage for dealing with Odoo's one2many, many2many and selection fields when using Laradoo (or ripcord)?
Specifically how one would use them with create() and update(). In Python, it seems as if these are dealt with using special tuple commands however for PHP documentation seems very hard to find for these types of things and it would be extremely helpful.
For illustrative purposes in my particular project, I haven't been able to figure out how to relate a CRM lead tag to a lead during the creation process using Laradoo:
$id = $odoo->create('crm.lead', [
'type' => 'lead',
'priority' => 0, <-- what do we pass here for this selection field?
'name' => 'Example',
'contact_name' => 'John Doe',
'phone' => '555-555-5555',
'email_from' => 'example#domain.com',
'description' => 'Just some text.',
'tag_ids' => [1], <-- What do we pass here for this one2many field?
]);
In the example above when trying to set the priority selection field to an int other than 0 fails and when trying to pass an array of tag_ids (1 is valid tag id in my project), the lead remains untagged.
First of all selection field values are just string values that need to be part of the field defined selection values.
The values for relational fields like Onetomany and Many2many are ruled by the command formated values that you could read at:
https://github.com/odoo/odoo/blob/11.0/odoo/models.py#L3020-L3055
For the php api usage with ripcord you could set the tag_ids field value like:
$id = $odoo->create('crm.lead', [
'type' => 'lead',
'priority' => '0',
'name' => 'Example',
'contact_name' => 'John Doe',
'phone' => '555-555-5555',
'email_from' => 'example#domain.com',
'description' => 'Just some text.',
'tag_ids' => array(array(4,1)),
]);
This translate as that 1 is the id of a known and already existing crm.lead.tag that you could link to the m2m tag_ids field using the command 4. This could also be expressed using command 6 to link multiple ids on the same command value:
'tag_ids' => array(array(6,0,array(1,2,3))),
where using command 4 it will be:
'tag_ids' => array(array(4,1), array(4,2), array(4,3)),
I am having a problem in updating values i get from web service ..
$collection = $modb->$table;
$collection->update(array("id" => (int)$row['id']),
array('$set' => array(
"user_id" => (int)$post_data_array['user_id'],
"story" => (int)$post_data_array['story'],
"surprize_sub1" => (int)$post_data_array['surprize_sub1'],
"surprize_sub2" => (int)$post_data_array['surprize_sub2'],
"surprize_sub3" => (int)$post_data_array['surprize_sub3'],
"exr_solve" => (int)$post_data_array['exr_solve'],
"exr_assessmnt" => (int)$post_data_array['exr_assessmnt'],
"exr_refresh" => (int)$post_data_array['exr_refresh'],
"sound_control" => (int)$post_data_array['sound_control'],
"clock_control" => (int)$post_data_array['clock_control'],
"switch_user" => (int)$post_data_array['switch_user'],
"exr_print" => (int)$post_data_array['exr_print'],
"write_on_wall" => (int)$post_data_array['write_on_wall'],
"switch_letter" => (int)$post_data_array['switch_letter'],
"view_controls" => (int)$post_data_array['view_controls'],
)));
I get these values from end users.. i want the specific field sent to be updated without loosing all the rest of data ..
in this code only sent data is set while removing the rest .. i want to change only sent ones by keeping the rest as they are, please advice
you need to use updateOne instead of update .
updateOne
Use the MongoDB\Collection::updateOne() method to update a single document matching a filter.
$collection = $modb->$table;
$collection->updateOne(array("id" => (int)$row['id']),
array('$set' => array(
// .... array elements
)));
Currently I am working on Elastic Search 2.0 for my current Project. MySqL Query As follows,
select user_id from users where subscription_type ! = ''
In This above query, I Need to write in Elastic Search, I am trying in elastic search but it getting
please find below code in elastic search
$query = array("from" => $start,
"size" => $recordslimit,
"sort" => array(array('id' => 'desc')),
"query" => array(
"filtered" => array(
"query" => array("match_all" => array()),
"filter" => array("bool" => array(
'must_not' => array(
array('term' => array('subscription_type' => ''))
)))
)));
please help me out with this situation
I see two possible scenarios:
If subscription type is null or doesn't appear in your documents, then you can use missing query instead of a term query in the must_not clause.
On the other hand if you would like to exclude those documents whose subscription_type field holds the empty string, then your query is correct but maybe your mapping isn't. Make sure that subscription_type is defined as not_analyzed in the mapping.
I'm trying to store my data in an empty database using Transactions. Now this doesn't work for me. This is my ERD: https://www.dropbox.com/s/pfakd7xplsvr7cc/db_erd.PNG
Notice that at first all three tables are empty. And I send the following array to the database:
array(
'Product' => array(
'slug' => 'c24b626d6701d3b07e30b233b989ff8811',
'product_name' => 'DAHLIA 5A',
'price_new' => '159.00',
'affiliate_url' => 'http://example.com/feed.xml',
'product_id_supplier' => 'c24b626d670133d3b07e30b2b989ff8811',
'supplier_id' => 'some_supplier',
'feedimport_id' => (int) 1
),
'Image' => array(
(int) 0 => array(
'image' => 'product_image.JPG'
)
),
'Term' => array(
'Term' => array(
(int) 0 => array(
'name' => 'Tommy Hilfiger'
)
)
)
)
Using $this->getDataSource(); . But it only fills the images and products table. If I look at the log file, it appears it tries to select from the products_terms table, after inserting the products and images table, and ofcourse it receives nothing back. And there it stops.... It doesn't try to insert in the terms table either.
Now if I look at tutorials like these: http://www.pabloleanomartinet.com/cakephp-2-x-saving-and-validating-a-habtm-relation-example/
It looks like I don't do anything wrong... But if I look closely it looks like the TAGS table in the tutorial is filled already.... So probably that's the problem? But I don't know how to get a Term ID first, before inserting the product and linking them together, using transactions....
Anyone who does?
Problem solved. It seems like the Terms table needs to be filled, else cakePHP doesn't know which term to connect to.
So the proper solution is to first check or the Term exists, else insert the Term in the Terms table, and then insert the products using HABTM (using the ID of the Term in the insert array), so the products_terms table will be filled also.
I have built an API that I want to test. By that reason I'm building a simple client to try out the different features (CRUD). Below is the function for updating a producer, which works fine. However, I also want to be able to update parts of a producer, e.g. address (/producers/8?method=put&address=milkyway).
The array producer always contains the same elements (name, address, zipcode etc) but I only want to update the producer with the elements in the array which contains of anything. What I mean with that is that if for example the name element in the array is empty then name shouldn't be included in *http_build_query*. If only the name element contains of anything then only name should be updated.
So, let's say that the array (except for id that of course is mandatory) contains of address. How can I dynamically add only that to *http_build_query* ?
Thanks in advance!
public function UpdateProducer($producer) {
$url = 'http://localhost/webbteknik2/Labb2/api/v1/producers/ . $producer['id'] . '?method=put';
$data = http_build_query(array(
'name' => $producer['name'],
'address' => $producer['address'],
'zipcode' => $producer['zipcode'],
'town' => $producer['town'],
'url' => $producer['url'],
'imgurl' => $producer['imgurl'],
'latitude' => $producer['latitude'],
'longitude' => $producer['longitude'],
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
...
the rest of the curl code
}
Note: I know this is bad coding in many ways, but as I said I only, asap want to be able to test the CRUD functionality through the client.
use array_filter to remove the empty elements....
$params = array(
'name' => $producer['name'],
'address' => $producer['address'],
'zipcode' => $producer['zipcode'],
'town' => $producer['town'],
'url' => $producer['url'],
'imgurl' => $producer['imgurl'],
'latitude' => $producer['latitude'],
'longitude' => $producer['longitude'],
);
$data = http_build_query(array_filter($params, 'is_null'));