当前位置: 首页>>代码示例>>PHP>>正文


PHP Configure::getGoogleDrive方法代码示例

本文整理汇总了PHP中Configure::getGoogleDrive方法的典型用法代码示例。如果您正苦于以下问题:PHP Configure::getGoogleDrive方法的具体用法?PHP Configure::getGoogleDrive怎么用?PHP Configure::getGoogleDrive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Configure的用法示例。


在下文中一共展示了Configure::getGoogleDrive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     require_once base_path('vendor/google/apiclient/src/Google/autoload.php');
     $googleDrive = Configure::getGoogleDrive();
     if (empty($googleDrive)) {
         return $this->error('Google Drive configure was empty.');
     } else {
         if (!isset($googleDrive['google_drive_email'])) {
             return $this->error('Google Drive email was not set.');
         } else {
             if (!isset($googleDrive['google_drive_key_file'])) {
                 return $this->error('Google Drive key file was not set.');
             } else {
                 if (!File::exists($googleDrive['google_drive_key_file'])) {
                     return $this->error("Google Drive key file cannot be found.\nPath: {$googleDrive['google_drive_key_file']}");
                 }
             }
         }
     }
     $auth = new Google_Auth_AssertionCredentials($googleDrive['google_drive_email'], [Google_Service_Drive::DRIVE, Google_Service_Drive::DRIVE_READONLY, Google_Service_Drive::DRIVE_FILE, Google_Service_Drive::DRIVE_METADATA_READONLY], File::get($googleDrive['google_drive_key_file']));
     $client = new Google_Client();
     $client->setAssertionCredentials($auth);
     $service = new Google_Service_Drive($client);
     $query = 'mimeType contains \'image\' and mimeType != \'image/svg+xml\'';
     $lastDate = VIImage::where('store', 'google-drive')->orderBy('id', 'desc')->pluck('created_at');
     if ($lastDate) {
         $lastDate = gmdate("Y-m-d\\TH:i:s", strtotime($lastDate));
         $query .= ' and modifiedDate > \'' . $lastDate . '\'';
     }
     $files = $service->files->listFiles(['q' => $query])->getItems();
     $arrInsert = $arrDelete = [];
     $this->getFiles($files, $arrInsert, $arrDelete);
     while (!empty($files->nextPageToken)) {
         $files = $service->files->listFiles(['q' => $query, 'pageToken' => $files->nextPageToken]);
         $this->getFiles($files, $arrInsert, $arrDelete);
     }
     if (!empty($arrDelete)) {
         $detailImages = $images = [];
         foreach ($arrDelete as $k => $file) {
             $image = VIImageDetail::select('image_id', 'detail_id')->where('path', $file)->first();
             if ($image) {
                 $detailImages[] = $image->detail_id;
                 $images[] = $image->image_id;
             }
         }
         VIImageDetail::destroy($detailImages);
         VIImage::destroy($images);
     }
     if (!empty($arrInsert)) {
         foreach ($arrInsert as $file) {
             $image = new VIImage();
             $image->name = $file['name'];
             $image->short_name = Str::slug($image->name);
             $image->store = 'google-drive';
             $image->save();
             $imageDetail = new VIImageDetail();
             $imageDetail->path = $file['link'];
             $imageDetail->width = $file['width'];
             $imageDetail->height = $file['height'];
             $imageDetail->size = $file['size'];
             $imageDetail->ratio = $file['width'] / $file['height'];
             $imageDetail->extension = $file['extension'];
             $imageDetail->type = 'main';
             $imageDetail->image_id = $image->id;
             $imageDetail->save();
         }
     }
     $this->info('Query: "' . $query . '".' . "\n" . 'Inserted ' . count($arrInsert) . ' images(s).' . "\n" . 'Deleted ' . count($arrDelete) . ' image(s).');
 }
开发者ID:nguyendaivu,项目名称:imagestock,代码行数:74,代码来源:GoogleDriveCommand.php


注:本文中的Configure::getGoogleDrive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。