當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。