Get Id file uploaded google drive job queue laravel - laravel

i am making an image storage function with laravel job queue via googledrive. i am trying to initialize and store my photo. It works with the code:
$filePut = file_get_contents($this->path);
Storage::cloud()->put($this->name, $filePut);
but i can't get the return id
i am changing to another method and here is my 2nd code:
public function handle(GoogleClient $googleDrive)
{
dd($googleDrive);
$driveService = new \Google_Service_Drive($googleDrive);
$fileMetadata = new \Google_Service_Drive_DriveFile([
'name' => $this->name,
]);
$file = $driveService->files->create($fileMetadata, [
'data' => file_get_contents($this->path),
'uploadType' => 'multipart',
'fields' => 'id',
]);
$driveService->getClient()->setUseBatch(true);
try {
$batch = $driveService->createBatch();
$userPermission = new \Google_Service_Drive_Permission([
'type' => 'anyone',
'role' => 'reader',
]);
$request = $driveService->permissions->create($file->id, $userPermission, ['fields' => 'id']);
$batch->add($request, 'user');
$results = $batch->execute();
} catch (\Exception $e) {
} finally {
$driveService->getClient()->setUseBatch(false);
}
I noticed the data received from dd($googleDrive) is no data :
App\Components\GoogleClient {#3225
#client: Google\Client {#3203
-auth: null
-http: null
-cache: null
-token: null
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => ""
"client_secret" => ""
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" => ""
I try to store it before the queue then the $drivegoogle data I get is as follows:
Google\Client {#3146
-auth: null
-http: null
-cache: null
-token: array:6 [
"access_token" => "*************************************************************************************"
"expires_in" => "*************************************************************************************"
"scope" => "*************************************************************************************"
"token_type" => "*************************************************************************************"
"created" => "*************************************************************************************"
"refresh_token" => "*************************************************************************************"
]
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => "*************************************************************************************"
"client_secret" => "*************************************************************************************"
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" =>
is there any workaround to get the id from the storage::put method, or is there another way to fix my current error, the error appears at new \Google_Service_Drive($googleDrive); constructor must be array or instance of Google\Client {"exception":"[object] (TypeError(code: 0): constructor must be array or instance of Google\\Client

$googleDrive = $googleDrive->getClient()

Related

because it shows Undefined offset: 0, seeder laravel?

I have the following for in which I create the records
foreach ($v as $k => $f){
if($v[$k] != false && $f['zip_code'] !=''){
$state = State::whereCode($f['code'])->get();
var_dump($state[0]->id);
\App\Models\ZipCodes::create([
'uuid' => Uuid::generate(4)->string,
'zip_code' => $f['zip_code'],
'city' => $f['city'],
'county' => $f['county'],
'state_id' => $state[0]->id,
]);
}
}
I have noticed that the error appears in the field 'state_id' => $ state [0] -> id
since if I comment and delete it from the table it doesn't give me the error.
In fact if I just leave
foreach ($v as $k => $f){
if($v[$k] != false && $f['zip_code'] !=''){
$state = State::whereCode($f['code'])->get();
var_dump($state[0]->id);
}
}
The same generates the error.

Where is the file after create by "$service->spreadsheets->create($requestBody)"

Thank you very much for reading this, its quite long!
I run my function:
public function createSpreadSheet()
{
$client = $this->getClient();
$service = new \Google_Service_Sheets($client);
// TODO: Assign values to desired properties of `requestBody`:
$requestBody = new \Google_Service_Sheets_Spreadsheet();
$response = $service->spreadsheets->create($requestBody);
echo '<pre>', var_export($response, true), '</pre>', "\n";
}
I got a result:
Google_Service_Sheets_Spreadsheet::__set_state(array(
'collection_key' => 'sheets',
'developerMetadataType' => 'Google_Service_Sheets_DeveloperMetadata',
'developerMetadataDataType' => 'array',
'namedRangesType' => 'Google_Service_Sheets_NamedRange',
'namedRangesDataType' => 'array',
'propertiesType' => 'Google_Service_Sheets_SpreadsheetProperties',
'propertiesDataType' => '',
'sheetsType' => 'Google_Service_Sheets_Sheet',
'sheetsDataType' => 'array',
'spreadsheetId' => '1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU',
'spreadsheetUrl' => 'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit',
'internal_gapi_mappings' =>
array (
),
modelData' =>
array (
),
'processed' =>
array (
),
'properties' =>
Google_Service_Sheets_SpreadsheetProperties::__set_state(array(
'autoRecalc' => 'ON_CHANGE',
'defaultFormatType' => 'Google_Service_Sheets_CellFormat',
'defaultFormatDataType' => '',
'iterativeCalculationSettingsType' => 'Google_Service_Sheets_IterativeCalculationSettings',
'iterativeCalculationSettingsDataType' => '',
'locale' => 'en_US',
'timeZone' => 'Etc/GMT',
'title' => 'Untitled spreadsheet',
'internal_gapi_mappings' =>
array (
),
'modelData' =>
array (
),
'processed' =>
array (
),
'defaultFormat' =>
Google_Service_Sheets_CellFormat::__set_state(array(
'backgroundColorType' => 'Google_Service_Sheets_Color',
'backgroundColorDataType' => '',
'bordersType' => 'Google_Service_Sheets_Borders',
'bordersDataType' => '',
'horizontalAlignment' => NULL,
'hyperlinkDisplayType' => NULL,
'numberFormatType' => 'Google_Service_Sheets_NumberFormat',
'numberFormatDataType' => '',
.........
.........
))
I access to the link it returned:
'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit'
it gives me this 'request access' page, then I press the request access
I open my email and get this:
Your message wasn't delivered to xxxxxx#xxxxxxxx.iam.gserviceaccount.com because the domain admanager-1x3x71x4x27x4.iam.gserviceaccount.com couldn't be found. Check for typos or unnecessary spaces and try again.
Is there something wrong and what should I do? I just want to open the file and check where it is.
Thank you very much!

Cakephp3 - Cant find $theme property that throws an error

I have upgraded from Cakephp3 v3 to v3.3 (using Composer) and I get the following error:
Deprecated (16384): Property $theme is deprecated.
Use $this->viewBuilder()->theme() instead in beforeRender().
[CORE/src/View/ViewVarsTrait.php, line 103]
But I can't find in my files where $theme is used. I have searched all my files for the keyword $theme and beforeRender, no relevant results.
This error is shown in all my pages, so it must be some file that is included in each one.
I have already searched on google for this issue, no relevant results either.
Has anyone else had this problem?
Full error stack:
$viewClass = null
$builder = object(Cake\View\ViewBuilder) {
[protected] _templatePath => 'Users'
[protected] _template => 'login'
[protected] _plugin => null
[protected] _theme => 'Orange'
[protected] _layout => null
[protected] _autoLayout => null
[protected] _layoutPath => null
[protected] _name => null
[protected] _className => null
[protected] _options => []
[protected] _helpers => []
}
$validViewOptions = [
(int) 0 => 'passedArgs'
]
$viewOptions = [
'passedArgs' => []
]
$option = 'passedArgs'
$this = object(App\Controller\UsersController) {
theme => 'Orange'
name => 'Users'
helpers => []
request => object(Cake\Network\Request) {}
response => object(Cake\Network\Response) {}
paginate => []
autoRender => false
components => []
View => null
plugin => null
passedArgs => []
modelClass => 'Users'
viewClass => null
viewVars => []
Flash => object(Cake\Controller\Component\FlashComponent) {}
Auth => object(Cake\Controller\Component\AuthComponent) {}
[protected] _responseClass => 'Cake\Network\Response'
[protected] _components => object(Cake\Controller\ComponentRegistry) {}
[protected] _validViewOptions => [
(int) 0 => 'passedArgs'
]
[protected] _eventManager => object(Cake\Event\EventManager) {}
[protected] _eventClass => '\Cake\Event\Event'
[protected] _tableLocator => object(Cake\ORM\Locator\TableLocator) {}
[protected] _modelFactories => [
'Table' => [
[maximum depth reached]
]
]
[protected] _modelType => 'Table'
[protected] _viewBuilder => object(Cake\View\ViewBuilder) {}
}
$deprecatedOptions = [
'layout' => 'layout',
'view' => 'template',
'theme' => 'theme',
'autoLayout' => 'autoLayout',
'viewPath' => 'templatePath',
'layoutPath' => 'layoutPath'
]
$new = 'theme'
$old = 'theme'
Cake\Controller\Controller::createView() - CORE/src/View/ViewVarsTrait.php, line 103
Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 616
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 131
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 99
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 65
[main] - ROOT/webroot/index.php, line 21
Turns out that in AppController a custom theme (Orange in my case) needs to be declared as:
public function beforeRender(Event $event)
{
$this->viewBuilder()->theme('Orange');
}
and not like
public $theme = 'Orange';
Many thanks to #arilia for helping me with this.

[cakePHP3]how to debug a failed save

This is my code , I have problems with making a simple save. The message is :( when i trying to save
$user = $this->Users->newEntity();
if($this->request->is('post'))
{
$user = $this->Users->patchEntity($user, $this->request->data);
if($this->Users->save($user))
{
$this->Flash->success(':)');
return $this->redirect(['controller' => 'Users', 'action' => 'index']);
}
else
{
$this->Flash->error(':(');
}
debug($this->request->data);
}
$this->set(compact('user'));
this is my table , I made a migration. All fields can be null
$table = $this->table('users');
$table->addColumn('first_name','string',array('limit'=>100))
->addColumn('last_name','string',array('limit'=>100))
->addColumn('email','string',array('limit'=>100))
->addColumn('password','string')
->addColumn('role','enum',array('values'=>'admin,user'))
->addColumn('active','boolean')
->addColumn('created','datetime')
->addColumn('modified','datetime')
->create();
this is my request data
[
'first_name' => 'wewe',
'last_name' => 'wewe',
'email' => 'wewe#wee.com',
'password' => 'wewewe',
'role' => 'admin',
'active' => '1'
]
I hope that you help me , I am very frustrated
EDIT: if i use print_r ($user->errors()); i get this...
Array ( [firts_name] => Array ( [_required] => This field is required ) )
Your error is in the name of your data, the request data is
'first_name' => 'wewe'"
your column name is "firts_name", its a typing error.

Yii2: How do I get the database properties of model attributes?

How do you get the database column properties of the attributes of a model? Like datatype, default value, size, etc.
You can use $customer_model->getTableSchema() or Customer::getTableSchema()
Provides you with something like this:
yii\db\TableSchema#1 (
[schemaName] => null
[name] => 'customers'
[fullName] => 'customers'
[primaryKey] => [
0 => 'customerID'
]
[sequenceName] => ''
[foreignKeys] => [
0 => [
0 => 'orders'
'ord_customerID' => 'customerID'
]
]
[columns] => [
'customerID' => yii\db\ColumnSchema#2 (
[name] => 'customerID'
[allowNull] => false
[type] => 'integer'
[phpType] => 'integer'
[dbType] => 'int(10) unsigned'
[defaultValue] => null
[enumValues] => null
[size] => 10
[precision] => 10
[scale] => null
[isPrimaryKey] => true
[autoIncrement] => true
[unsigned] => true
[comment] => ''
)
...

Resources