I am partially updating the document using the following structure
$params = [
'index' => self::$currentIndex[self::INDEX_TYPE_SEARCH],
'type' => self::TYPE_PRODUCT,
'id' => $product_id,
'body' => [
'script' => 'ctx._source.coupons += coupon',
'params' => ['coupon' => array($product_body)],
]
];
However I am getting the following error:
remote_transport_exception:
[Gee][127.0.0.1:9300][indices:data/write/update[s]]
Any idea if the structure is incorrect?
If you wan't to add values to an array than you can do this,
$params['id'] = $product_id;
$params['body'] = array(
'script' => array(
"inline" => "ctx._source.coupons.add(params.coupon)",
"lang" => "painless",
"params" => ['coupon' => array($product_body)]
)
);
This thould work as it worked for me.
Related
I am using a Database tables component for Laravel, however I want to do a check within the blade view, but can't seem to figure out the best approach for that. Since the array is created in the view and not in the controller.
I have an array and an object value. And if that object value is true it should present an extra line within the array.
What I have is the following:
"title" => "view_template"
What I want to produce is the following
[
'sometitle1' => 'someview1',
'sometitle2' => 'someview2', //this part needs if statement is true
'sometitle3' => 'someview3'
]
I am thinking of something like this
[
'sometitle1' => 'someview1',
($obj->has_this_field) ? ['sometitle2' => 'someview2']:
'sometitle3' => 'someview3'
]
But it doesn't do that obviously. I normally solve this with array_push in the controller. What would be the best approach since this is in a blade view.
I also tried this
[
'sometitle1' => 'someview1',
($obj->has_this_field) ? ['sometitle2' => 'someview2']:
'sometitle3' => 'someview3'
]
And this will obviously not work
[
'sometitle1' => 'someview1',
($obj->has_this_field) ? 'sometitle2' => 'someview2':
'sometitle3' => 'someview3'
]
#include('partials.panel', [
'header' => trans('general.information'),
'partial' => 'partials.show-tabs',
'partialData' => [
'root' => 'equipment.equipment.panels',
'tabs' => [
'general' => 'general',
'advanced' => 'maintenance',
(!$equipment->has_running_hours) ? ['runninghours' => 'runninghours']:
'history' => 'history',
]
]
])
This is what I want to produce
[
'general' => 'general',
'runninghours' => 'runninghours',
'history' => 'history'
]
Why you don't make an array first with #php //your Logic #endphp then pass that array to your #include part
Something like below.
#php
$array = [
'header' => trans('general.information'),
'partial' => 'partials.show-tabs',
'partialData' => [
'root' => 'equipment.equipment.panels',
'tabs' => [
'general' => 'general',
'advanced' => 'maintenance',
]
]
];
if(!$equipment->has_running_hours)
{
$array['partialData']['tabs']['runninghours'] = 'runninghours';
}
else
{
$array['partialData']['tabs']['history'] = 'history';
}
#endphp
Now pass this to your #include
#include('partials.panel',$array)
I go through this documentation "https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry"
And tried to add journal entry with line having customer as shown in the below code:
$journal_entry_create['TxnDate'] = date('Y-m-d');
$journal_entry_line = array(
'Amount' => $amount,
'DetailType' => 'JournalEntryLineDetail',
'JournalEntryLineDetail' => array(
'PostingType' => Credit,
'Entity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'type' => 'Customer',
'value' => "2",
'name' => 'Abc'
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
);
$journal_entry_lines[] = $journal_entry_line;
$journal_entry_create['Line'] = $journal_entry_lines;
$journal_entry_receipt_create = QBJournalEntry::create($journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
Without EntityRef its working fine but when I add EntityRef its giving me error "Message: Passed array has no key for 'Value' when contructing an ReferenceType"
Only just came across this problem myself. They did fix this issue but didn't seem to document it at all or tell anyone. Found the fix in the source code. You need to use "JournalEntryEntity" instead of "Entity" under "JournalEntryLineDetail", like so:
'JournalEntryLineDetail' => array(
'PostingType' => "Credit",
'JournalEntryEntity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'value' => "2"
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
Also I used the FacadeHelper from the V3 of the PHP SDK (I'm not sure if it'll work with the method you were using):
use QuickBooksOnline\API\Facades\FacadeHelper;
...
$journal_entry_receipt_create = FacadeHelper::reflectArrayToObject('JournalEntry', $journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
I know this is probably too late for you OP but hopefully it helps someone else!
I am facing the issue of multiple request at same time.I am checking in DB if this data exists then not insert the same record.
Using cakephp 2.6 version
$userdata = $this->MobappFan->find('first', array(
'conditions' => array(
'MobappFan.id' => 123,
'MobappFan.mobapp_id' => 234,
'MobappFan.deleted' => 0
),
'fields' => array('MobappFan.id', 'MobappFan.status', 'MobappFan.blocked'),
'contain' => false
)
);
if(!$userdata) {
$this->MobappFan->save($this->request->data);
}
But due to same request with same parameters is not able to find the existing record.
Please help
Thanks
I think basically you just want to not check in the current posted id
you can do this as below
$userdata = $this->MobappFan->find('first', array(
'conditions' => array(
'MobappFan.id' => 123,
'MobappFan.id !=' => $this->request->data['MobappFan']['id'],
'MobappFan.mobapp_id' => 234,
'MobappFan.deleted' => 0
),
'fields' => array('MobappFan.id', 'MobappFan.status', 'MobappFan.blocked'),
'contain' => false
)
);
if(!$userdata) {
$this->MobappFan->save($this->request->data);
}
or
$userdata = $this->MobappFan->find('first', array(
'conditions' => array(
'MobappFan.id' => 123,
"NOT" => array( 'MobappFan.id' => $this->request->data['MobappFan']['id']),
'MobappFan.mobapp_id' => 234,
'MobappFan.deleted' => 0
),
'fields' => array('MobappFan.id', 'MobappFan.status', 'MobappFan.blocked'),
'contain' => false
)
);
if(!$userdata) {
$this->MobappFan->save($this->request->data);
}
Hope this helps. If you can explain more what you need then I can write a better conditions or you can check details here
$options = array(
'UserData' => base64_encode('test'),
'SecurityGroupIds' => [AWS_REGIONS[$region]['security_group']],
'InstanceType' => AWS_REGIONS[$region]['instance_type'],
'ImageId' => AWS_REGIONS[$region]['ami'],
'MaxCount' => $to_launch,
'MinCount' => 1,
//'EbsOptimized' => true,
'SubnetId' => AWS_REGIONS[$region]['subnet_id'],
'Tags' => [['Key' => 'task', 'Value' => $task],['Key' => 'Name', 'Value' => $task]],
'InstanceInitiatedShutdownBehavior' => 'terminate'
);
$response = $client->runInstances($options);
I am using the "latest" Ec2Client
It launches fine but the Tags are completely ignored.
I suspect an error within the EC2 API but I am not that experienced.
Maybe someone with experience can help me out ?
This is because Ec2Client::runInstances does not have tags option
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#runinstances
You would need to make a separate call to tag newly created instance(s) using Ec2Client::createTags:
$result = $client->createTags(array(
'DryRun' => true || false,
// Resources is required
'Resources' => array('string', ... ),
// Tags is required
'Tags' => array(
array(
'Key' => 'string',
'Value' => 'string',
),
// ... repeated
),
));
Read more here:
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#createtags
When i try to add new documents to an index type , i loose existing documents which are overwritten by the new added ones . The problem can be related to the id of each added document ??
Here is the code :
$elasticaClient = new \Elastica\Client(array(
'host' => $this->container->getParameter('elastic_host'),
'port' => $this->container->getParameter('elastic_port')
));
$elasticaIndex = $elasticaClient->getIndex('app');
$elasticaIndex->create(
array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('lowercase', 'mySnowball')
),
'searchAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('standard', 'lowercase', 'mySnowball')
)
),
'filter' => array(
'mySnowball' => array(
'type' => 'snowball',
'language' => 'German'
)
)
)
),
true
);
$elasticaType = $elasticaIndex->getType('type');
$mapping = new \Elastica\Type\Mapping();
$mapping->setType($elasticaType);
$mapping->setParam('index_analyzer', 'indexAnalyzer');
$mapping->setParam('search_analyzer', 'searchAnalyzer');
$mapping->setProperties(array(
'id' => array('type' => 'string'),
'title' => array('type' => 'string'),
'duration' => array('type' => 'string'),
'start' => array('type' => 'string'),
'end' => array('type' => 'string'),
));
// Send mapping to type
$mapping->send();
$documents = array();
foreach($medias as $media) {
$id = uniqid() ;
$documents[] = new \Elastica\Document(
$id,
array(
'id' => $id,
'title' => $media['title'],
'duration' => $media['duration'],
'start' => $media['start'],
'end' => $media['end'],
)
);
}
$elasticaType->addDocuments($documents);
$elasticaType->getIndex()->refresh();
Please i need your help . Thank you
PHP does not recommend using uniqid for this use case. Since you are wanting a random, safe id, let Elasticsearch do it for you. The Elastica Document construct method notes that the id field is optional. So don't pass it and let Elasticsearch issue the id.
Several things
$elasticaIndex->create (....) you only have to enter it once. Index is unique after creating the index that you can comment or generate a different index and other things. I leave an example that works.
class PersistencyElastic
{
private $conection;
public function __construct()
{
$this->conection = new \Elastica\Client(['host' => '127.0.0.1', 'port' => 9200]);
}
public function save($ msg)
{
// $ msg is an array with whatever you want inside
$index = $this->conection->getIndex('googlephotos');
// This is the index I created, it's called googlephotos
// $index->create(array (), true);
$type = $index->getType('googlephotos');
$type->addDocument(new Document (uniqid ('id _', false), $msg, $type, $index));
$index->refresh();
}
}