How to update Amazon CloudFront distribution - php

I want to update the status of an Amazon CloudFront distribution using the updatedistribution method provided by AWS.
I don't know default value of all the required parameters.
My code is:
list($before, $after) = explode('.', $domain, 2);
$domain_Items = "*." . $after;
$result = $client->updateDistribution([
'DistributionConfig' =>
[
'Aliases' =>
[
'Items' => [$domain_Items, $after],
'Quantity' => 2
],
'CallerReference' => $domain,
'Comment' => 'custom domain for ' . $domain,
'Enabled' => false,
'PriceClass' => 'PriceClass_All',
'CacheBehaviors' => [
'Items' => [
[
'AllowedMethods' =>
[
'CachedMethods' =>
[
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Items' => ['HEAD', 'GET', 'OPTIONS', 'PUT', 'POST', 'PATCH', 'DELETE'],
'Quantity' => 7,
],
'Compress' => true,
'DefaultTTL' => 0,
//'FieldLevelEncryptionId' => '<string>',
'ForwardedValues' => [
'Cookies' => [
'Forward' => 'all',
'WhitelistedNames' => [
'Quantity' => 5,
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
],
],
'Headers' =>
[
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
'Quantity' => 5
],
'QueryString' => true,
'QueryStringCacheKeys' => [
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
'Quantity' => 5
],
],
'LambdaFunctionAssociations' => [
'Items' => [
[
'EventType' => 'viewer-request',
'IncludeBody' => true,
'LambdaFunctionARN' => '', //<string>
]
],
'Quantity' => 1,
],
'MaxTTL' => 0,
'MinTTL' => 0,
'PathPattern' => '', //<string>
'SmoothStreaming' => true,
'TargetOriginId' => 'ELB-saglus-test-uat-web-783948842',
'TrustedSigners' => [
'Enabled' => false,
//'Items' => ['<string>'],
'Quantity' => 0,
],
'ViewerProtocolPolicy' => 'redirect-to-https',
],
],
'Quantity' => 1,
],
'DefaultCacheBehavior' =>
[
'AllowedMethods' =>
[
'CachedMethods' =>
[
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Items' => ['HEAD', 'GET', 'OPTIONS', 'PUT', 'POST', 'PATCH', 'DELETE'],
'Quantity' => 7,
],
'Compress' => true,
'DefaultTTL' => 0,
'FieldLevelEncryptionId' => '',
'ForwardedValues' =>
[
'Cookies' =>
[
'Forward' => 'all'
],
'WhitelistedNames' => [
'Quantity' => 5,
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
],
'Headers' =>
[
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
'Quantity' => 5,
],
'QueryString' => true,
'QueryStringCacheKeys' => [
'Items' => ['Host', 'Referer', 'Orign', 'User-Agent', 'HTTP_REFERER'],
'Quantity' => 5, // REQUIRED
],
],
'LambdaFunctionAssociations' => [
'Items' => [
[
'EventType' => 'viewer-request',
'IncludeBody' => false,
'LambdaFunctionARN' => '', // REQUIRED <string>
]
],
'Quantity' => 1, // REQUIRED
],
'MaxTTL' => 600,
'MinTTL' => 0,
'SmoothStreaming' => false,
'TargetOriginId' => 'ELB-saglus-test-uat-web-783948842',
'TrustedSigners' =>
[
'Enabled' => false,
'Quantity' => 0
],
'ViewerProtocolPolicy' => 'redirect-to-https'
],
'DefaultRootObject' => '',
'HttpVersion' => 'http2',
'IsIPV6Enabled' => false,
'Logging' => [
'Bucket' => 'saglus-aws-logs.s3.amazonaws.com', // REQUIRED
'Enabled' => true, // REQUIRED
'IncludeCookies' => true, // REQUIRED
'Prefix' => 'logs-for-' . $domain, // REQUIRED
],
'Origins' =>
[
'Items' =>
[
[
'CustomHeaders' =>
[
'Items' =>
[
[
'HeaderName' => 'X-Origin-Verify',
'HeaderValue' => 'cnxpwcausbtobmebhebadbergdifn'
],
],
'Quantity' => 1
],
'CustomOriginConfig' =>
[
'HTTPPort' => 80,
'HTTPSPort' => 443,
'OriginKeepaliveTimeout' => 5,
'OriginProtocolPolicy' => 'http-only',
'OriginReadTimeout' => 120,
'OriginSslProtocols' =>
[
'Items' => ['TLSv1'],
'Quantity' => 1
],
],
'DomainName' => 'saglus-test-uat-web-783948842.us-east-1.elb.amazonaws.com',
'Id' => 'ELB-saglus-test-uat-web-783948842',
'OriginPath' => ''
],
],
'Quantity' => 1,
],
'WebACLId' => '108e7697-00db-4330-8d55-bbe57ca94e44'
],
'Id' => $distribution_id,
'IfMatch' => $ETag,
]);
However, I get the error:
Reference link: updatedistribution in AWS SDK for PHP 3.x

$client = new Aws\CloudFront\CloudFrontClient([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => $this->AcmKey,
'secret' => $this->AcmSecret
]
]);
// $id = 'E2SYUN95DWJFXC';
$id = $business_custom_data->distribution_id;
try {
$result = $client->getDistribution([
'Id' => $id,
]);
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}
$currentConfig = $result["Distribution"]["DistributionConfig"];
$ETag = $result["ETag"];
$distribution = [
'CallerReference' => $currentConfig["CallerReference"], // REQUIRED
'Comment' => $currentConfig["Comment"], // REQUIRED
'DefaultCacheBehavior' => $currentConfig["DefaultCacheBehavior"], // REQUIRED
'DefaultRootObject' => $currentConfig["DefaultRootObject"],
//'Enabled' => $currentConfig["Enabled"], // REQUIRED
'Enabled' => False, // REQUIRED
'Origins' => $currentConfig["Origins"], // REQUIRED
'Aliases' => $currentConfig["Aliases"],
'CustomErrorResponses' => $currentConfig["CustomErrorResponses"],
'HttpVersion' => $currentConfig["HttpVersion"],
'CacheBehaviors' => $currentConfig["CacheBehaviors"],
'Logging' => $currentConfig["Logging"],
'PriceClass' => $currentConfig["PriceClass"],
'Restrictions' => $currentConfig["Restrictions"],
'ViewerCertificate' => $currentConfig["ViewerCertificate"],
'WebACLId' => $currentConfig["WebACLId"],
];
try {
$result = $client->updateDistribution([
'DistributionConfig' => $distribution,
'Id' => $id,
'IfMatch' => $ETag
]);
$status = true;
//var_dump($result);
//die;
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}

Related

Set description for Stripe checkout session

I developped the last Stripe module for the end of the year as they ask, but since I put it, I haven't any more the description and the name of the customer in Stripe.
Do you know how can I put it again ?
This is my code in PHP :
try {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'customer_email' => $email,
'line_items' => [[
'price_data' => [
'product_data' => [
'name' => $custom['item_name'],
'metadata' => [
'pro_id' => $custom['item_name']
]
],
'unit_amount' => (isset($custom['amountTotal']) ? $custom['amountTotal'] : $custom['amount'])*100,
'currency' => $custom['currency_code'],
],
'quantity' => 1,
'description' => $custom['item_name'],
]],
'mode' => 'payment',
'success_url' => $url,
'cancel_url' => $request->cancel,
], ['stripe_account' => $_SESSION['param']->stripeUID]);
}catch(Exception $e) {
$api_error = $e->getMessage();
}
if(empty($api_error) && $session){
$response = array(
'status' => 1,
'message' => 'Checkout Session created successfully!',
'sessionId' => $session['id']
);
}else{
$response = array(
'status' => 0,
'error' => array(
'message' => 'Checkout Session creation failed! '.$api_error
)
);
}
And this is what I have now
You should be able to set it here: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-description
just add this line so the description appears, I mark it with asterisks or in bold
'payment_method_types' => ['card'],
'**payment_intent_data**' => [
'description' => ''.$productName.''
],
'line_items' => [[
'price_data' => [
'product_data' => [
'name' => $productName,
'description' => ''.$productName.'',
'metadata' => [
'pro_id' => $productID
]
],
'unit_amount' => $stripeAmount,
'currency' => $currency,
],
'quantity' => 1,
'description' => $descripcion,
]],
'mode' => 'payment',

Docusign not prefilling documents before sending

I am having issues when sending documents for a recipient to sign it. The documents should be prefilled using the data from my database which works fine. I know this because when I var_dump $this->textTabs I can see the data. $global is false.
The issue I am having is that when the recipient receives an email to sign the document, the fields which should be prefilled are blank. The Data Label matches the tabLabel in the code below and image
$this->textTabs = [
[
'tabLabel' => 'RegisteredName',
'value' => $contactData->company->name,
'global' => $global,
],
[
'tabLabel' => 'NumberOfEmployees',
'value' => $contactData->company->employee_size,
'global' => $global,
],
[
'tabLabel' => 'RegisteredNumber',
'value' => $contactData->company->reg_no,
'global' => $global,
],
[
'tabLabel' => 'SupplyAddress',
'value' => $supplyAddress_1 . $supplyAddress_2 . $supplyCity . $supplyTown . $supplyCounty . $supplyPostcode,
'global' => $global,
],
[
'tabLabel' => 'SicCode',
'value' => $contactData->company->gapSite->scat_code,
'global' => $global,
],
[
'tabLabel' => 'Recipient_UserTitle',
'value' => $title,
'global' => $global,
],
[
'tabLabel' => 'Recipient_UserName',
'value' => $title . $firstName . $lastName,
'global' => $global,
],
[
'tabLabel' => 'Recipient_Email',
'value' => $contactData->email,
'global' => $global,
],
[
'tabLabel' => 'ContactTelephone',
'value' => $contactData->telephone,
'global' => $global,
],
];
private function send(string $status): ?array
{
try {
return Docusign::createEnvelope([
'templateId' => $this->templateId,
'emailSubject' => $this->emailSubject,
'status' => $status,
'templateRoles' => [
[
'name' => $this->recipient['name'],
'email' => $this->recipient['email'],
'roleName' => 'Client',
'tabs' => [
'textTabs' => $this->textTabs,
/* 'signHereTabs' => [
[
"xPosition" => 400,
"yPosition" => 263,
"documentId" => 1,
"pageNumber" => 6
]
],
*/
]
]
],
'eventNotification' => [
'url' => 'https://webhook.site/697fabec-145a-491f-87ce-1d62be82b298',
'LoggingEnabled' => true,
'RequireAcknowledgment' => true,
'UseSoapInterface' => false,
'IncludeCertificateWithSoap' => false,
'SignMessageWithX509Cert' => false,
'includeDocuments' => true,
'includeEnvelopeVoidReason' => true,
'includeTimeZone' => true,
'includeSenderAccountAsCustomField' => true,
'includeDocumentFields' => true,
'includeCertificateOfCompletion' => true,
'envelopeEventStatusCode' => $this->getRecipientEvents(),
'recipientEvents' => $this->getEventNotification(),
]
]);
} catch (\Exception $e) {
}
}
The fact That recipient receives the email to sign the document, already eliminate any issue to do with my code but why is it not prefilling with the data?
After a while, I decided to create a new docusign account and this seems to have solved the issue. I believe my account was bugger or maybe some technical issue on docusign,

Multiple identical entitiy relation

I've got a products, attributes, and product_attributes table.
Each product can have multiple attributes and these relations were stored in product_attributes, so far so good.
But a product can have the same attribute multiple times. I just only can link different attributes to a product.
For example:
Audi(product) has Wheel(attribute): Amount(joinData) = 2;
Value(joinData) = "front";
And
Audi(product) has Wheel(attribute): Amount(joinData) = 2;
Value(joinData) = "rear";
Only the attribute wheel with value rear is saved the front wheels are lost.
No errors in controller.
This is the output of $this->request->getData()
/src/Controller/ProductsController.php (line 62)
[
'type_id' => '12',
'name' => 'Audi',
'thumbnail' => '',
'image' => '',
'attributes' => [
(int) 0 => [
'unique_id' => '9',
'_joinData' => [
'amount' => '2',
'value' => '1',
'information' => 'front'
]
],
(int) 1 => [
'unique_id' => '9',
'_joinData' => [
'amount' => '2',
'value' => '1',
'information' => 'rear'
]
]
]
]
This is the output of $product after patchEntity:
object(App\Model\Entity\Product) {
'type_id' => (int) 12,
'name' => 'Audi',
'thumbnail' => '',
'image' => '',
'attributes' => [
(int) 0 => object(App\Model\Entity\Attribute) {
'unique_id' => (int) 9,
'category_id' => (int) 8,
'name' => 'VDSL2',
'unit' => '',
'_joinData' => object(App\Model\Entity\ProductsAttribute) {
'amount' => (int) 2,
'value' => (float) 1,
'information' => 'rear',
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'amount' => true,
'value' => true,
'information' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ProductsAttributes'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => [
'amount' => '2',
'value' => '0',
'information' => 'front'
]
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Attributes'
},
(int) 1 => object(App\Model\Entity\Attribute) {
'unique_id' => (int) 9,
'category_id' => (int) 8,
'name' => 'VDSL2',
'unit' => '',
'_joinData' => object(App\Model\Entity\ProductsAttribute) {
'amount' => (int) 2,
'value' => (float) 1,
'information' => 'rear',
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'amount' => true,
'value' => true,
'information' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ProductsAttributes'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => [
'amount' => '2',
'value' => '0',
'information' => 'front'
]
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Attributes'
}
],
'[new]' => true,
'[accessible]' => [
'type_id' => true,
'name' => true,
'thumbnail' => true,
'image' => true,
'type' => true,
'attributes' => true
],
'[dirty]' => [
'type_id' => true,
'name' => true,
'thumbnail' => true,
'image' => true,
'attributes' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Products'
}
ProductController Add function:
public function add(){
$product = $this->Products->newEntity();
if ($this->request->is('post')) {
$product = $this->Products->patchEntity($product, $this->request->getData(), [
'associated' => [
'Attributes',
'Attributes._joinData'
]
]);
/*debug($this->request->getData());
debug($product);
die();*/
if ($this->Products->save($product)) {
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$types = $this->Products->Types->find('list', ['limit' => 200]);
$attributes = $this->Products->Attributes->find('list', ['limit' => 200]);
$this->set(compact('product', 'types', 'attributes'));
}
It has something to do with my relations.
Product Table:
$this->belongsToMany('Attributes', [
'foreignKey' => 'product_id',
'targetForeignKey' => 'attribute_id',
'joinTable' => 'products_attributes'
]);
Attribute Table:
$this->belongsToMany('Products', [
'foreignKey' => 'attribute_id',
'targetForeignKey' => 'product_id',
'joinTable' => 'products_attributes'
]);
These are the attributes product_attributes have in the DB:
unique_iq INT,
product_id INT,
attribute_id INT,
amount INT,
value DOUBLE,
information VARCHAR(150)
Save Strategy doesn't solve my problem. Still same result.
Just a workaround but it should work. Waiting for a more cake way
Since you basically want to fill products and product_attributes tables you can set a new relationship this way
Product Table:
$this->hasMany('ProductsAttributes', [ /* configure keys here */ ]);
And shape you data this way
[
'type_id' => '12',
'name' => 'Audi',
'thumbnail' => '',
'image' => '',
'products_attributes' => [
[
'attribute_id' => '9',
'amount' => '2',
'value' => '1',
'information' => 'front'
],
[
'attribute_id' => '9',
'amount' => '2',
'value' => '1',
'information' => 'rear'
]
]
]
This will create a new row in products and two new rows in product_attributes

How to perform Recursion to Nth level?

Here is my single database structure.
I have one array which I will export in one file by var_export.
This is a sample array,
return [
'menus' => [
'products' => [
'name' => 'Products',
'link' => 'cctv.html',
'show' => true,
],
'companies' => [
'name' => 'Companies',
'link' => 'companies.html',
'show' => true,
],
],
'products' => [
'section_enabled' => [
'featured_products', 'categories', 'news', 'latest_products', 'case_studies', 'expert_commentary',
'videos', 'companies', 'topics',
],
'pages' => [
'child_category_page' => [
'middle' => [
'left' => [
'class' => 'col-md-9',
'sections' => [
[
'folder' => '',
'element' => 'page_heading',
'variables' => ['page_heading', 'articles'],
],
],
],
],
],
'product_profile_page' => [
'middle' => [
'left' => [
'class' => 'col-md-9',
'sections' => [
[
'folder' => '',
'element' => 'page_heading',
'variables' => ['page_heading'],
],
[
'folder' => 'products',
'element' => 'specifications',
'variables' => ['specifications', 'filters'],
],
],
],
],
],
],
],
'news' => [
'news_types' => [
'expert_commentary' => 'Etary',
'applications' => 'Mon',
'security_beat' => 'SB',
'round_table' => 'RT',
'case_studies' => [
'type' => 'Marcation',
'label' => 'Casies',
],
],
'url_lookup_values' => [
'caudies' => [
'value' => 'Marklication',
'config' => 'castudies',
],
],
],
];
I got the recursion trick from here.
But it doesn't solve my problem.
Here is what I have tried,
function generate_site_config()
{
$data = DB::table("SITE_CONFIGS")->where("parent_id", 0)->get();
$desired_array = [];
get_tree_site_configs($data,$desired_array,0,0);
// file_put_contents(config_path() . DIRECTORY_SEPARATOR . "frontend_configs_demo.php", '<?php return ' . var_export($data, true) . ';');
echo "success";die;
}
function get_tree_site_configs($inputArray, &$outputArray, $parent = 0, $level = 0){
foreach($inputArray as $cc_id => $sub_arr){
if($sub_arr->parent_id == $parent){
$outputArray[] = $sub_arr;
if($sub_arr->variable_value == ''){
$inputArray = DB::table("SITE_CONFIGS")->where("parent_id", $sub_arr->id)->get();
get_tree_site_configs($inputArray, $outputArray, $sub_arr->id, $level + 1);
}else{
pr($sub_arr);
pr($outputArray);die;
}
}
}
}
NOTE: chain will go until variable_value == '', if variable_value found then it stops the tree at that end, then it will look for other parents which are dangling.

Elasticsearch php giving error when setting 2 criterias in must clause

I am trying to add multiple criterion to ElasticSearch PHP in must clause, but it is giving me a 500 Error.
My params are:
$params = ['index' => 'smartjn',
'type' => 'feed_details',
'size' => 10,
'body' => [
'sort' => [
'sorter' => [
'order' => 'desc',
'mode' => 'max'
]
],
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']],
[ '_id' => [
'$lt' => new MongoDB\BSON\ObjectId($documentid)
]
]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
]
]
];
Please note that this works if I remove the second criteria in must clause i.e.
$params = ['index' => 'smartjn',
'type' => 'feed_details',
'size' => 10,
'body' => [
'sort' => [
'sorter' => [
'order' => 'desc',
'mode' => 'max'
]
],
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
]
]
];
Any idea what am I missing?
Thanks
check this out.
'query' => ['bool' => [
'must' => [
['match' => ['approvalStatus' => 'approved']],
[ 'ids' => [
'values' => [new MongoDB\BSON\ObjectId($documentid)]
]
]
],
'must_not' => ['term' => ['muteFeedUserIds' => $userID]],
'must_not' => ['term' => ['muteUserIds' => $userID]]
]
If that doesnt work i am giving you the raw as i am not good with elasticphp
{
"query": {
"bool": {
"must": [
{
"ids": {
"type": "type_of_index"
"values": ["AVbqtjXfoKQ0pubF_-NA"]
}
}
]
}
}
}
type is optional
Just add this ids part under must area.

Categories