Amazon S3 and Yii2 - php

I created a code to use Amazon S3 using this composer component:
https://github.com/2amigos/yii2-resource-manager-component
This worked very well.
But I changed my server and when I upload a image to Amazon S3 I received this error:
PHP Fatal Error – yii\base\ErrorException
Class 'Aws\S3\Enum\CannedAcl' not found
I did not change anything of code, I dont understand why this error, I cant find a solution
How can I fix it?
This is the complete error :
PHP Fatal Error – yii\base\ErrorException
Class 'Aws\S3\Enum\CannedAcl' not found
1. in /opt/app-root/src/admapps/vendor/2amigos/yii2-resource-manager-component/AmazonS3ResourceManager.php at line 78
69707172737475767778798081828384858687 * #return \Guzzle\Service\Resource\Model
*/
public function save($file, $name, $options = [])
{
$options = ArrayHelper::merge([
'Bucket' => $this->bucket,
'Key' => $name,
'SourceFile' => $file->tempName,
'ACL' => CannedAcl::PUBLIC_READ // default to ACL public read
], $options);
$this->getClient()->putObject($options);
}
/**
* Removes a file
* #param string $name the name of the file to remove
* #return boolean
*/
2. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – app\controllers\BeersController::actionUploadlogobeer()
3. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – call_user_func_array:{/opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php:55}()
4. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Controller.php at line 154 – yii\base\InlineAction::runWithParams()
5. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Module.php at line 454 – yii\base\Controller::runAction()
6. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/web/Application.php at line 87 – yii\base\Module::runAction()
7. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Application.php at line 375 – yii\web\Application::handleRequest()
8. in /opt/app-root/src/admapps/web/index.php at line 13 – yii\base\Application::run()
78910111213require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../helpers/Utils.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();

Posted by Bizley
This extension uses "aws/aws-sdk-php": "2.5.2" and it's very old (at GitHub version 3.18 is latest). AWS said they've removed CannedAcl in version 3 so it should not make impact on 2.5.2 (it is present in 2.5.2). Anyway there is the same issue reported about this github.com/2amigos/yii2-resource-manager-component/issues/10 – Bizley

Related

Create function using external php library | shipping

I use Inpost ShipX PHP SDK php library one courier company to post/create shipping using API.
With this code I can get shipping label and save, this working correct:
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('var/labels/paczkomaty_label.pdf', $labelResponse->getBody()->__toString());
Now I try also get tracking number for created shipping.
I try add to above code:
$trackingResponse = $api->shipments()->tracking()->get($shipmentData['id']);
var_dump($trackingResponse);
But after post I get:
An uncaught Exception was encountered
Type: InvalidArgumentException
Message: tracking resource not found
Filename: /vendor/imper86/php-inpost-api/src/Resource/AbstractResource.php
Line Number: 66
Can anyone check this library and help me build the function correctly or give me a hint how i can check the resource to build the right function?
Code for __call inside /vendor/imper86/php-inpost-api/src/Resource/AbstractResource.php#66:
$className = $this->reflection->getName() . '\\' . ucfirst($name);
In your case it would be Shipments\\Tracking, but there is no such class.
Try doing
$api->tracking()->shippingHistory()->get($shipmentData['id']);
Basically what you see inside src/Resouce dir you can call as method.
I have just performed static analysis of code/structure, may be wrong

Error in Wordpress - elementor after ugrading PHP 7.4

After upgrading to PHP 7.4, elemntor started giving error
url: www.aldon.ltd/
Cloud Service: GCP
Server: Openlitespeed Wordpress
Linux: Ubuntu 20.04 LTS
Notice: Trying to access array offset on value of type null in /var/www/html/wp-content/plugins/elementor/includes/base/controls-stack.php on line 1449
Notice: Trying to access array offset on value of type null in /var/www/html/wp-content/plugins/elementor/includes/base/controls-stack.php on line 1451
Except this notice shown at the top of webpage, all other functions are working as expected.
Code causing error
/**
* End controls section.
*
* Used to close an existing open controls section. When you use this method
* it stops adding new controls to this section.
*
* This method should be used inside _register_controls().
*
* #since 1.4.0
* #access public
*/
Public function end_controls_section() {
$stack_name = $this->get_name();
// Save the current section for the action.
$current_section = $this->current_section;
$section_id = $current_section['section'];
$args = [
'tab' => $current_section['tab'],
];
Error Log at /usr/local/lsws/logs/error.log
PHP Notice: wp_deregister_script was called incorrectorrectly. Do not deregister the jquery-core script in the administration area. To target the front-end theme, use the wp_enqueue_scrip>
PHP Notice: /var/www/html/wp-content/plugins/elementor/includes/base/controls-stack.php on line 1449
PHP Notice: /var/www/html/wp-content/plugins/elementor/includes/base/controls-stack.php on line 1451
I resolved it for a temporary solution. Changing line no. 1204 from
if ( $dynamic_property ) ) {
to
if ( $dynamic_property && isset($settings[ $control_name ][ $dynamic_property ]) ) {

constant errors using insights Facebook marketing api (php)

I get this error when I try to run my app locally via xampp. Just to note, I generated code using quick start from developers.facebook so there shouldnt be errors within the code itself.
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 83
Warning: fwrite() expects parameter 1 to be resource, string given in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 182
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message '(#100) Filtering field delivery_info is invalid. Please refer to the document https://developers.facebook.com/docs/marketing-api/insights for valid filters.' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php:144 Stack trace: #0 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(162): FacebookAds\Http\Request->execute() #3 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(204): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 C:\xampp\htdocs\working\vendor\facebo in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php on line 144
I'm starting to suspect that I got the wrong files from the composer. or there might be a problem with my setup. The contents of my composer.json just before I ran composer.phar was
{
"require": {
"facebook/php-sdk-v4" : "~5.0",
"facebook/php-ads-sdk": "2.10.*"
}
}
I'm going to attach the code below just in case you guys want to look at it as well. The only thing that I modified there is adding the app_id since it was not included from the generated code.
<?php
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdsInsights;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$app_id = '274807576345457';
$access_token = 'EAAD575ZC4O3EBAChoTmxC0nwdbvjXLRUKGGXgmZA6HZBFjmKZB6F3olMIe2mG2dgQSb9SudtN7EeeO8gzo7zgFZB0EHZAwTrg4wsIKsJxB3bhw5fonZC3YCZA0C4InaCSOgW42i4PswQa3BZCctMZBYTh94TwGLxGg8gZAZAj4zZC5PfgXl0kw6eOuxW4g1L41NOwtRDGS7O7FsJZBWZCM0IAe00WSf';
$ad_account_id = 'act_113902719358005';
$app_secret = 'aeb42f19e0f33f0937c023fff12909c4';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
'cost_per_result',
'cost_per_total_action',
'cpm',
'cpp',
'frequency',
'impressions',
'impressions_auto_refresh',
'impressions_gross',
'reach',
'relevance_score:score',
'relevance_score:positive_feedback',
'relevance_score:negative_feedback',
'result_rate',
'results',
'social_impressions',
'social_reach',
'spend',
'today_spend',
'total_actions',
'total_unique_actions',
'actions:video_view',
'video_10_sec_watched_actions:video_view',
'delivery',
);
$params = array(
'level' => 'campaign',
'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active','limited'))),
'breakdowns' => array(),
'time_range' => array('since' => '2017-09-28','until' => '2017-09-29'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
if comment this part
[json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);]
; the error stop.
if make [var_export((new AdAccount($ad_account_id));] show full array
I experienced the exact same error. I believe (in my case) this was because I was also using an older PHP version (5.6) resulting in some compatibility issues.
I solved this by changing the version of php-ads-sdk from 2.8 to "8.*" (or change it to any recent version according to when you are reading this solution) in composer.json.
Then call sudo composer update in your terminal

"Constant CRLF already defined" error when using php-resque with Laravel

I'm running php-resque together with Laravel 3 on Ubuntu 12.04.
Problem: When a job is enqueued in resque, I get the following error:
Unhandled Exception
Message:
Constant CRLF already defined
Location:
/var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
What does the error mean and how can we solve it?
PHP
// Enqueue in Resque
$data = array(
'name' => $name,
'email' => $email,
'created_at' => DB::raw('NOW()')
);
Resque::enqueue('queue', 'exampleWorker', $data);
However when I try to enqueue a job using artisan, it works!
Task
class Queue_Task
{
public function run()
{
// Autoload composer vendors.
require path('composer').DS.'autoload.php';
$args = array('name' => 'John Smith');
Resque::enqueue('MyAppName', 'ExampleWorker', $args);
echo "Resque job queued.\n";
return;
}
}
Output
PHP Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Resque job queued.
It's a guess, but I'd say in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php there's a second define('CRLF', 'something') on line 10 that should probably be commented out if you want these two pieces of software to work together.

Problems trying to use the Kohana pagination module

I have downloaded the Kohana Pagination module from Git and have been having some issues trying to use it.
I moved it into the modules folder and have updated my bootstrap to include the module...
'pagination' => MODPATH.'kohana-pagination',
I have the following code that loads some messages from a simple table with pagination...
public function action_index()
{
$content = View::factory('welcome')
->bind('messages', $messages)
->bind('pager_links', $pager_links);
$message = new Model_Message;
$message_count = $message->count_all();
$pagination = Pagination::factory(array(
'total_items' => $message_count,
'items_per_page' => 3,
));
$pager_links = $pagination->render();
$messages = $message->get_all($pagination->items_per_page, $pagination->offset);
$this->template->content = $content;
}
When I run load this in my browser, I get the following error message...
ErrorException [ Fatal Error ]: 1Call to undefined method Kohana::config()
MODPATH\kohana-pagination\classes\kohana\pagination.php [ 87 ]
82 * #return array config settings
83 */
84 public function config_group($group = 'default')
85 {
86 // Load the pagination config file
87 $config_file = Kohana::config('pagination');
88
89 // Initialize the $config array
90 $config['group'] = (string) $group;
91
92 // Recursively load requested config groups
{PHP internal call} » Kohana_Core::shutdown_handler()
If I remove the code relating to the pagination, the page loads the data fine from the database. Any pointers here would be great.
Update
Found this link: https://github.com/kloopko/kohana-pagination, on the back of Ikke, so cheers for the help folks.
Appears that the previously bundled pagination module has been removed, found the kohana-pagination module which has been updated to cater for 3.2.
Hope that helps someone else just starting out. :)
The issue is just the config system has changed for version 3.2. Most modules can be fixed by simply updating
$config_file = Kohana::config('pagination');
to
$config_file = Kohana::$config->load('pagination');
Let me update you the steps to resolve with Kohana paging.
Go to modules/pagination/classes/kohana/pagination.php
Change the
$config_file = Kohana::config('pagination');
to
$config_file = Kohana::$config->load('pagination');
in the same page at the line 199
change this line to
return URL::site(Request::current()->uri).URL::query(array($this->config['current_page']['key'] => $page));
to
return URL::site(Request::current()->uri()).URL::query(array($this->config['current_page']['key'] => $page));
Add uri braces.
This resolved my issue. thank you.

Categories