示例#1
0
 /**
  * Update remote file
  *
  * @param	   integer	$projectid	Project ID
  * @param	   string	$service	Service name (google or dropbox)
  * @param	   integer	$uid		User ID
  * @param	   string	$remoteid	Remote resource ID
  * @param	   array	$local		Array of local file info
  * @param	   string	$parentId	Parent folder ID
  * @param	   boolean	$convert	Convert for remote editing? (Google only)
  *
  * @return	   array
  */
 public function updateRemoteFile($projectid = NULL, $service = 'google', $uid = 0, $remoteid = 0, $local = array(), $parentId = 0, $convert = false)
 {
     if (!$projectid || !$remoteid || empty($local) || !$parentId) {
         return false;
     }
     // Get api
     $apiService = $this->getAPI($service, $uid);
     if (!$apiService) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_API_UNAVAILABLE'));
         return false;
     }
     // Parse incoming
     $title = basename($local['local_path']);
     $localPath = $local['fullPath'];
     $mimeType = $local['mimeType'];
     // Collector for created item metadata
     $metadata = array();
     $success = 0;
     // Perform request
     if ($service == 'google') {
         // Check if content really changed
         try {
             $check = $apiService->files->get($remoteid);
             if ($check['labels']['trashed']) {
                 $success = Google::untrashItem($apiService, $remoteid);
             } elseif ($check && isset($check['md5Checksum']) && isset($local['md5Checksum']) && $check['md5Checksum'] == $local['md5Checksum']) {
                 $success = $remoteid;
             }
         } catch (Exception $e) {
             return false;
         }
         // There was a change in content, update
         if (!$success) {
             $success = Google::updateFile($apiService, $this->_client[$service], $remoteid, $title, $localPath, $mimeType, $parentId, $metadata, $convert);
         }
     }
     if (!$success) {
         return false;
     }
     $remote_md5 = isset($metadata) && isset($metadata['md5Checksum']) ? $metadata['md5Checksum'] : NULL;
     $remote_modified = isset($metadata) && isset($metadata['modifiedDate']) ? gmdate('Y-m-d H:i:s', strtotime($metadata['modifiedDate'])) : NULL;
     $remote_format = isset($metadata) && isset($metadata['mimeType']) ? $metadata['mimeType'] : NULL;
     $converted = isset($metadata) && preg_match("/google-apps/", $remote_format) && !preg_match("/.folder/", $remote_format) ? 1 : 0;
     // Update connection record
     $objRFile = new \Components\Projects\Tables\RemoteFile($this->_db);
     $update = $objRFile->updateRecord($projectid, $service, $remoteid, $local['local_path'], 'file', $uid, $parentId, $title, $remote_md5, $local['md5'], $converted, $remote_format, $local['mimeType'], $remote_modified);
     return $success;
 }