public static function getFileListFromDb($cloud_id = false)
 {
     $params = ['user_id' => Yii::$app->user->model->id];
     if ($cloud_id) {
         $params['cloud_id'] = $cloud_id;
     }
     $files = CloudFiles::findAll($params);
     return $files ?: [];
 }
 public function saveFile()
 {
     $name = explode('/', $this->file['path']);
     $this->file_name = $name[count($name) - 1];
     $uri = '/dropbox/file/' . $this->file_name;
     if ($this->fileFromDb = $this->fileExist($name)) {
         if ($this->isModified()) {
             $cloudFile = $this->fileFromDb;
         } else {
             return true;
         }
     } else {
         $cloudFile = new CloudFiles();
         $cloudFile->setAttributes(['user_id' => $this->user_id, 'cloud_user_id' => $this->cloud_user_id, 'cloud_id' => self::CLOUD_ID]);
     }
     $cloudFile->setAttributes(['name' => $this->file_name, 'created' => strtotime(isset($this->file['client_mtime']) ? $this->file['client_mtime'] : $this->file['modified']), 'modified' => strtotime($this->file['modified']), 'extension' => $this->file['is_dir'] ? 'folder' : $this->file['mime_type'], 'size' => $this->file['bytes'], 'uri' => $uri, 'path' => $this->file['path'], 'is_dir' => $this->file['is_dir'], 'json_file' => json_encode($this->file), 'hash' => $this->file['rev']]);
     return $cloudFile->save();
 }
 public function getFiles($folderName = '/', $getJson = false, $proactiveUpdate = false)
 {
     try {
         if ($folderMetadata = $this->hasChangesInDropbox($folderName, $proactiveUpdate)) {
             $dropboxUserFiles = $this->getFileListFromDb($folderName, $folderMetadata);
             $this->dropboxUserAccess->drive_hash = $folderMetadata['hash'];
             $this->dropboxUserAccess->save();
             $CloudFiles = new CloudFiles();
             $CloudFiles->saveCloudFiles(['files' => $folderMetadata['contents'], 'user_id' => $dropboxUserFiles->user_id, 'cloud_user_id' => $dropboxUserFiles->dropbox_user_id, 'cloud_id' => CloudFiles::DROPBOX]);
         }
         $CloudFiles = CloudFiles::getFileListFromDb(CloudFiles::DROPBOX);
         if ($getJson) {
             return json_encode($CloudFiles);
         }
         return $CloudFiles;
     } catch (Exception $e) {
         throw new CHttpException(402, 'Недействительные данные авторизации!');
     }
 }
 public function getFiles($getJson = false, $proactiveUpdate = false)
 {
     if ($drive_hash = $this->hasChangesInOnedrive() or $proactiveUpdate) {
         $header = ['Authorization: Bearer ' . TestOnedriveInit::getTestUserToken()];
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, self::ONERIVE_API_URL . '/drive/root/children');
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $content = curl_exec($ch);
         curl_close($ch);
         $responseAsArray = json_decode($content, true);
         $this->onedriveUserAccess->drive_hash = $drive_hash;
         $this->onedriveUserAccess->save();
         $CloudFiles = new CloudFiles();
         $CloudFiles->saveCloudFiles(['files' => $responseAsArray['value'], 'user_id' => Yii::$app->user->model->id, 'cloud_user_id' => $this->getOnedriveUserId(), 'cloud_id' => CloudFiles::ONEDRIVE]);
     }
     $CloudFiles = CloudFiles::getFileListFromDb(CloudFiles::ONEDRIVE);
     return $CloudFiles;
 }
 public function actionUpdatefilelistfromcloud()
 {
     CloudFiles::updateFileListFromCloud();
     return true;
 }