Blame view

sources/apps/files_external/lib/swift.php 11.9 KB
03e52840d   Kload   Init
1
  <?php
31b7f2792   Kload   Upgrade to ownclo...
2

03e52840d   Kload   Init
3
  /**
31b7f2792   Kload   Upgrade to ownclo...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   * ownCloud
   *
   * @author Christian Berendt
   * @copyright 2013 Christian Berendt berendt@b1-systems.de
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
   * License as published by the Free Software Foundation; either
   * version 3 of the License, or any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
   *
   * You should have received a copy of the GNU Affero General Public
   * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
03e52840d   Kload   Init
21
22
23
   */
  
  namespace OC\Files\Storage;
6d9380f96   Cédric Dupont   Update sources OC...
24
25
26
27
28
29
  use Guzzle\Http\Exception\ClientErrorResponseException;
  use OpenCloud;
  use OpenCloud\Common\Exceptions;
  use OpenCloud\OpenStack;
  use OpenCloud\ObjectStore\Resource\DataObject;
  use OpenCloud\ObjectStore\Exception;
03e52840d   Kload   Init
30

31b7f2792   Kload   Upgrade to ownclo...
31
  class Swift extends \OC\Files\Storage\Common {
6d9380f96   Cédric Dupont   Update sources OC...
32
33
34
  	/**
  	 * @var \OpenCloud\ObjectStore\Service
  	 */
31b7f2792   Kload   Upgrade to ownclo...
35
  	private $connection;
6d9380f96   Cédric Dupont   Update sources OC...
36
37
38
  	/**
  	 * @var \OpenCloud\ObjectStore\Resource\Container
  	 */
31b7f2792   Kload   Upgrade to ownclo...
39
  	private $container;
6d9380f96   Cédric Dupont   Update sources OC...
40
41
42
  	/**
  	 * @var \OpenCloud\OpenStack
  	 */
31b7f2792   Kload   Upgrade to ownclo...
43
  	private $anchor;
6d9380f96   Cédric Dupont   Update sources OC...
44
45
46
  	/**
  	 * @var string
  	 */
31b7f2792   Kload   Upgrade to ownclo...
47
  	private $bucket;
6d9380f96   Cédric Dupont   Update sources OC...
48
49
50
  	/**
  	 * @var array
  	 */
31b7f2792   Kload   Upgrade to ownclo...
51
  	private static $tmpFiles = array();
6d9380f96   Cédric Dupont   Update sources OC...
52
53
54
  	/**
  	 * @param string $path
  	 */
31b7f2792   Kload   Upgrade to ownclo...
55
56
57
58
59
  	private function normalizePath($path) {
  		$path = trim($path, '/');
  
  		if (!$path) {
  			$path = '.';
03e52840d   Kload   Init
60
  		}
31b7f2792   Kload   Upgrade to ownclo...
61

6d9380f96   Cédric Dupont   Update sources OC...
62
  		$path = str_replace('#', '%23', $path);
31b7f2792   Kload   Upgrade to ownclo...
63
  		return $path;
03e52840d   Kload   Init
64
  	}
6d9380f96   Cédric Dupont   Update sources OC...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  	const SUBCONTAINER_FILE='.subcontainers';
  
  	/**
  	 * translate directory path to container name
  	 * @param string $path
  	 * @return string
  	 */
  	private function getContainerName($path) {
  		$path=trim(trim($this->root, '/') . "/".$path, '/.');
  		return str_replace('/', '\\', $path);
  	}
  
  	/**
  	 * @param string $path
  	 */
31b7f2792   Kload   Upgrade to ownclo...
80
81
  	private function doesObjectExist($path) {
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
82
  			$this->container->getPartialObject($path);
31b7f2792   Kload   Upgrade to ownclo...
83
  			return true;
6d9380f96   Cédric Dupont   Update sources OC...
84
  		} catch (ClientErrorResponseException $e) {
31b7f2792   Kload   Upgrade to ownclo...
85
86
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  			return false;
03e52840d   Kload   Init
87
88
  		}
  	}
31b7f2792   Kload   Upgrade to ownclo...
89
90
91
92
93
  	public function __construct($params) {
  		if ((!isset($params['key']) and !isset($params['password']))
  		 	or !isset($params['user']) or !isset($params['bucket'])
  			or !isset($params['region'])) {
  			throw new \Exception("API Key or password, Username, Bucket and Region have to be configured.");
03e52840d   Kload   Init
94
  		}
03e52840d   Kload   Init
95

31b7f2792   Kload   Upgrade to ownclo...
96
97
  		$this->id = 'swift::' . $params['user'] . md5($params['bucket']);
  		$this->bucket = $params['bucket'];
03e52840d   Kload   Init
98

31b7f2792   Kload   Upgrade to ownclo...
99
100
101
  		if (!isset($params['url'])) {
  			$params['url'] = 'https://identity.api.rackspacecloud.com/v2.0/';
  		}
03e52840d   Kload   Init
102

31b7f2792   Kload   Upgrade to ownclo...
103
104
105
  		if (!isset($params['service_name'])) {
  			$params['service_name'] = 'cloudFiles';
  		}
03e52840d   Kload   Init
106

31b7f2792   Kload   Upgrade to ownclo...
107
108
  		$settings = array(
  			'username' => $params['user'],
31b7f2792   Kload   Upgrade to ownclo...
109
110
111
112
113
114
  		);
  
  		if (isset($params['password'])) {
  			$settings['password'] = $params['password'];
  		} else if (isset($params['key'])) {
  			$settings['apiKey'] = $params['key'];
03e52840d   Kload   Init
115
  		}
31b7f2792   Kload   Upgrade to ownclo...
116
117
118
  
  		if (isset($params['tenant'])) {
  			$settings['tenantName'] = $params['tenant'];
03e52840d   Kload   Init
119
  		}
03e52840d   Kload   Init
120

31b7f2792   Kload   Upgrade to ownclo...
121
  		if (isset($params['timeout'])) {
6d9380f96   Cédric Dupont   Update sources OC...
122
  			$settings['timeout'] = $params['timeout'];
03e52840d   Kload   Init
123
  		}
31b7f2792   Kload   Upgrade to ownclo...
124

6d9380f96   Cédric Dupont   Update sources OC...
125
126
127
  		$this->anchor = new OpenStack($params['url'], $settings);
  
  		$this->connection = $this->anchor->objectStoreService($params['service_name'], $params['region']);
31b7f2792   Kload   Upgrade to ownclo...
128

03e52840d   Kload   Init
129
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
130
131
132
  			$this->container = $this->connection->getContainer($this->bucket);
  		} catch (ClientErrorResponseException $e) {
  			$this->container = $this->connection->createContainer($this->bucket);
03e52840d   Kload   Init
133
  		}
31b7f2792   Kload   Upgrade to ownclo...
134
135
136
  		if (!$this->file_exists('.')) {
  			$this->mkdir('.');
  		}
03e52840d   Kload   Init
137
  	}
31b7f2792   Kload   Upgrade to ownclo...
138
139
140
141
  	public function mkdir($path) {
  		$path = $this->normalizePath($path);
  
  		if ($this->is_dir($path)) {
03e52840d   Kload   Init
142
143
  			return false;
  		}
31b7f2792   Kload   Upgrade to ownclo...
144
145
146
  
  		if($path !== '.') {
  			$path .= '/';
03e52840d   Kload   Init
147
  		}
31b7f2792   Kload   Upgrade to ownclo...
148
149
  
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
150
151
152
153
  			$customHeaders = array('content-type' => 'httpd/unix-directory');
  			$metadataHeaders = DataObject::stockHeaders(array());
  			$allHeaders = $customHeaders + $metadataHeaders;
  			$this->container->uploadObject($path, '', $allHeaders);
31b7f2792   Kload   Upgrade to ownclo...
154
155
  		} catch (Exceptions\CreateUpdateError $e) {
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
03e52840d   Kload   Init
156
  			return false;
03e52840d   Kload   Init
157
  		}
03e52840d   Kload   Init
158
159
  		return true;
  	}
31b7f2792   Kload   Upgrade to ownclo...
160
161
  	public function file_exists($path) {
  		$path = $this->normalizePath($path);
03e52840d   Kload   Init
162

31b7f2792   Kload   Upgrade to ownclo...
163
164
  		if ($path !== '.' && $this->is_dir($path)) {
  			$path .= '/';
03e52840d   Kload   Init
165
  		}
31b7f2792   Kload   Upgrade to ownclo...
166
  		return $this->doesObjectExist($path);
03e52840d   Kload   Init
167
  	}
31b7f2792   Kload   Upgrade to ownclo...
168
169
170
171
172
  	public function rmdir($path) {
  		$path = $this->normalizePath($path);
  
  		if (!$this->is_dir($path)) {
  			return false;
03e52840d   Kload   Init
173
  		}
03e52840d   Kload   Init
174

31b7f2792   Kload   Upgrade to ownclo...
175
176
177
178
179
  		$dh = $this->opendir($path);
  		while ($file = readdir($dh)) {
  			if ($file === '.' || $file === '..') {
  				continue;
  			}
03e52840d   Kload   Init
180

31b7f2792   Kload   Upgrade to ownclo...
181
182
183
184
185
186
  			if ($this->is_dir($path . '/' . $file)) {
  				$this->rmdir($path . '/' . $file);
  			} else {
  				$this->unlink($path . '/' . $file);
  			}
  		}
03e52840d   Kload   Init
187

31b7f2792   Kload   Upgrade to ownclo...
188
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
189
  			$this->container->dataObject()->setName($path . '/')->delete();
31b7f2792   Kload   Upgrade to ownclo...
190
191
192
  		} catch (Exceptions\DeleteError $e) {
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  			return false;
03e52840d   Kload   Init
193
  		}
03e52840d   Kload   Init
194

31b7f2792   Kload   Upgrade to ownclo...
195
  		return true;
03e52840d   Kload   Init
196
  	}
31b7f2792   Kload   Upgrade to ownclo...
197
198
  	public function opendir($path) {
  		$path = $this->normalizePath($path);
03e52840d   Kload   Init
199

31b7f2792   Kload   Upgrade to ownclo...
200
201
  		if ($path === '.') {
  			$path = '';
03e52840d   Kload   Init
202
  		} else {
31b7f2792   Kload   Upgrade to ownclo...
203
  			$path .= '/';
03e52840d   Kload   Init
204
  		}
03e52840d   Kload   Init
205

6d9380f96   Cédric Dupont   Update sources OC...
206
  		$path = str_replace('%23', '#', $path); // the prefix is sent as a query param, so revert the encoding of #
31b7f2792   Kload   Upgrade to ownclo...
207
208
  		try {
  			$files = array();
6d9380f96   Cédric Dupont   Update sources OC...
209
210
  			/** @var OpenCloud\Common\Collection $objects */
  			$objects = $this->container->objectList(array(
31b7f2792   Kload   Upgrade to ownclo...
211
212
213
  				'prefix' => $path,
  				'delimiter' => '/'
  			));
6d9380f96   Cédric Dupont   Update sources OC...
214
215
216
  			/** @var OpenCloud\ObjectStore\Resource\DataObject $object */
  			foreach ($objects as $object) {
  				$file = basename($object->getName());
31b7f2792   Kload   Upgrade to ownclo...
217
218
219
  				if ($file !== basename($path)) {
  					$files[] = $file;
  				}
03e52840d   Kload   Init
220
  			}
31b7f2792   Kload   Upgrade to ownclo...
221
222
223
224
225
  			\OC\Files\Stream\Dir::register('swift' . $path, $files);
  			return opendir('fakedir://swift' . $path);
  		} catch (Exception $e) {
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  			return false;
03e52840d   Kload   Init
226
  		}
31b7f2792   Kload   Upgrade to ownclo...
227

03e52840d   Kload   Init
228
  	}
31b7f2792   Kload   Upgrade to ownclo...
229
230
  	public function stat($path) {
  		$path = $this->normalizePath($path);
03e52840d   Kload   Init
231

31b7f2792   Kload   Upgrade to ownclo...
232
233
  		if ($this->is_dir($path) && $path != '.') {
  			$path .= '/';
03e52840d   Kload   Init
234
  		}
03e52840d   Kload   Init
235

31b7f2792   Kload   Upgrade to ownclo...
236
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
237
238
  			$object = $this->container->getPartialObject($path);
  		} catch (ClientErrorResponseException $e) {
31b7f2792   Kload   Upgrade to ownclo...
239
240
241
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  			return false;
  		}
03e52840d   Kload   Init
242

6d9380f96   Cédric Dupont   Update sources OC...
243
244
245
246
247
248
249
250
251
252
  		$dateTime = \DateTime::createFromFormat(\DateTime::RFC1123, $object->getLastModified());
  		if ($dateTime !== false) {
  			$mtime = $dateTime->getTimestamp();
  		} else {
  			$mtime = null;
  		}
  		$objectMetadata = $object->getMetadata();
  		$metaTimestamp = $objectMetadata->getProperty('timestamp');
  		if (isset($metaTimestamp)) {
  			$mtime = $metaTimestamp;
03e52840d   Kload   Init
253
  		}
03e52840d   Kload   Init
254

837968727   Kload   [enh] Upgrade to ...
255
256
257
  		if (!empty($mtime)) {
  			$mtime = floor($mtime);
  		}
31b7f2792   Kload   Upgrade to ownclo...
258
  		$stat = array();
6d9380f96   Cédric Dupont   Update sources OC...
259
  		$stat['size'] = (int) $object->getContentLength();
31b7f2792   Kload   Upgrade to ownclo...
260
261
262
  		$stat['mtime'] = $mtime;
  		$stat['atime'] = time();
  		return $stat;
03e52840d   Kload   Init
263
  	}
31b7f2792   Kload   Upgrade to ownclo...
264
265
  	public function filetype($path) {
  		$path = $this->normalizePath($path);
03e52840d   Kload   Init
266

31b7f2792   Kload   Upgrade to ownclo...
267
268
  		if ($path !== '.' && $this->doesObjectExist($path)) {
  			return 'file';
03e52840d   Kload   Init
269
  		}
03e52840d   Kload   Init
270

31b7f2792   Kload   Upgrade to ownclo...
271
272
  		if ($path !== '.') {
  			$path .= '/';
03e52840d   Kload   Init
273
  		}
03e52840d   Kload   Init
274

31b7f2792   Kload   Upgrade to ownclo...
275
276
  		if ($this->doesObjectExist($path)) {
  			return 'dir';
03e52840d   Kload   Init
277
  		}
03e52840d   Kload   Init
278
279
280
  	}
  
  	public function unlink($path) {
31b7f2792   Kload   Upgrade to ownclo...
281
  		$path = $this->normalizePath($path);
6d9380f96   Cédric Dupont   Update sources OC...
282
283
284
  		if ($this->is_dir($path)) {
  			return $this->rmdir($path);
  		}
31b7f2792   Kload   Upgrade to ownclo...
285
  		try {
6d9380f96   Cédric Dupont   Update sources OC...
286
287
  			$this->container->dataObject()->setName($path)->delete();
  		} catch (ClientErrorResponseException $e) {
31b7f2792   Kload   Upgrade to ownclo...
288
  			\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
03e52840d   Kload   Init
289
290
  			return false;
  		}
31b7f2792   Kload   Upgrade to ownclo...
291
292
  
  		return true;
03e52840d   Kload   Init
293
294
295
  	}
  
  	public function fopen($path, $mode) {
31b7f2792   Kload   Upgrade to ownclo...
296
297
298
  		$path = $this->normalizePath($path);
  
  		switch ($mode) {
03e52840d   Kload   Init
299
300
  			case 'r':
  			case 'rb':
31b7f2792   Kload   Upgrade to ownclo...
301
302
303
  				$tmpFile = \OC_Helper::tmpFile();
  				self::$tmpFiles[$tmpFile] = $path;
  				try {
6d9380f96   Cédric Dupont   Update sources OC...
304
305
306
307
308
  					$object = $this->container->getObject($path);
  				} catch (ClientErrorResponseException $e) {
  					\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  					return false;
  				} catch (Exception\ObjectNotFoundException $e) {
31b7f2792   Kload   Upgrade to ownclo...
309
  					\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
03e52840d   Kload   Init
310
311
  					return false;
  				}
31b7f2792   Kload   Upgrade to ownclo...
312
  				try {
6d9380f96   Cédric Dupont   Update sources OC...
313
314
315
316
  					$objectContent = $object->getContent();
  					$objectContent->rewind();
  					$stream = $objectContent->getStream();
  					file_put_contents($tmpFile, $stream);
31b7f2792   Kload   Upgrade to ownclo...
317
318
319
320
321
  				} catch (Exceptions\IOError $e) {
  					\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  					return false;
  				}
  				return fopen($tmpFile, 'r');
03e52840d   Kload   Init
322
323
324
325
326
327
328
329
330
331
332
333
  			case 'w':
  			case 'wb':
  			case 'a':
  			case 'ab':
  			case 'r+':
  			case 'w+':
  			case 'wb+':
  			case 'a+':
  			case 'x':
  			case 'x+':
  			case 'c':
  			case 'c+':
31b7f2792   Kload   Upgrade to ownclo...
334
335
336
337
338
339
  				if (strrpos($path, '.') !== false) {
  					$ext = substr($path, strrpos($path, '.'));
  				} else {
  					$ext = '';
  				}
  				$tmpFile = \OC_Helper::tmpFile($ext);
03e52840d   Kload   Init
340
  				\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
31b7f2792   Kload   Upgrade to ownclo...
341
342
343
344
345
346
347
  				if ($this->file_exists($path)) {
  					$source = $this->fopen($path, 'r');
  					file_put_contents($tmpFile, $source);
  				}
  				self::$tmpFiles[$tmpFile] = $path;
  
  				return fopen('close://' . $tmpFile, $mode);
03e52840d   Kload   Init
348
349
  		}
  	}
31b7f2792   Kload   Upgrade to ownclo...
350
351
352
353
354
355
  	public function getMimeType($path) {
  		$path = $this->normalizePath($path);
  
  		if ($this->is_dir($path)) {
  			return 'httpd/unix-directory';
  		} else if ($this->file_exists($path)) {
6d9380f96   Cédric Dupont   Update sources OC...
356
357
  			$object = $this->container->getPartialObject($path);
  			return $object->getContentType();
03e52840d   Kload   Init
358
  		}
31b7f2792   Kload   Upgrade to ownclo...
359
  		return false;
03e52840d   Kload   Init
360
  	}
31b7f2792   Kload   Upgrade to ownclo...
361
362
  	public function touch($path, $mtime = null) {
  		$path = $this->normalizePath($path);
6d9380f96   Cédric Dupont   Update sources OC...
363
364
365
366
  		if (is_null($mtime)) {
  			$mtime = time();
  		}
  		$metadata = array('timestamp' => $mtime);
31b7f2792   Kload   Upgrade to ownclo...
367
368
369
370
  		if ($this->file_exists($path)) {
  			if ($this->is_dir($path) && $path != '.') {
  				$path .= '/';
  			}
6d9380f96   Cédric Dupont   Update sources OC...
371
372
373
  			$object = $this->container->getPartialObject($path);
  			$object->saveMetadata($metadata);
  			return true;
31b7f2792   Kload   Upgrade to ownclo...
374
  		} else {
6d9380f96   Cédric Dupont   Update sources OC...
375
376
377
378
379
  			$customHeaders = array('content-type' => 'text/plain');
  			$metadataHeaders = DataObject::stockHeaders($metadata);
  			$allHeaders = $customHeaders + $metadataHeaders;
  			$this->container->uploadObject($path, '', $allHeaders);
  			return true;
03e52840d   Kload   Init
380
  		}
31b7f2792   Kload   Upgrade to ownclo...
381
382
383
384
385
  	}
  
  	public function copy($path1, $path2) {
  		$path1 = $this->normalizePath($path1);
  		$path2 = $this->normalizePath($path2);
6d9380f96   Cédric Dupont   Update sources OC...
386
387
388
389
390
  		$fileType = $this->filetype($path1);
  		if ($fileType === 'file') {
  
  			// make way
  			$this->unlink($path2);
31b7f2792   Kload   Upgrade to ownclo...
391
  			try {
6d9380f96   Cédric Dupont   Update sources OC...
392
393
394
  				$source = $this->container->getPartialObject($path1);
  				$source->copy($this->bucket.'/'.$path2);
  			} catch (ClientErrorResponseException $e) {
31b7f2792   Kload   Upgrade to ownclo...
395
396
397
  				\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  				return false;
  			}
6d9380f96   Cédric Dupont   Update sources OC...
398
399
400
401
402
  
  		} else if ($fileType === 'dir') {
  
  			// make way
  			$this->unlink($path2);
31b7f2792   Kload   Upgrade to ownclo...
403
404
  
  			try {
6d9380f96   Cédric Dupont   Update sources OC...
405
406
407
  				$source = $this->container->getPartialObject($path1 . '/');
  				$source->copy($this->bucket.'/'.$path2 . '/');
  			} catch (ClientErrorResponseException $e) {
31b7f2792   Kload   Upgrade to ownclo...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
  				\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
  				return false;
  			}
  
  			$dh = $this->opendir($path1);
  			while ($file = readdir($dh)) {
  				if ($file === '.' || $file === '..') {
  					continue;
  				}
  
  				$source = $path1 . '/' . $file;
  				$target = $path2 . '/' . $file;
  				$this->copy($source, $target);
  			}
6d9380f96   Cédric Dupont   Update sources OC...
422
423
424
425
  
  		} else {
  			//file does not exist
  			return false;
03e52840d   Kload   Init
426
  		}
31b7f2792   Kload   Upgrade to ownclo...
427
  		return true;
03e52840d   Kload   Init
428
429
430
  	}
  
  	public function rename($path1, $path2) {
31b7f2792   Kload   Upgrade to ownclo...
431
432
  		$path1 = $this->normalizePath($path1);
  		$path2 = $this->normalizePath($path2);
03e52840d   Kload   Init
433

6d9380f96   Cédric Dupont   Update sources OC...
434
435
436
437
438
439
440
441
  		$fileType = $this->filetype($path1);
  
  		if ($fileType === 'dir' || $fileType === 'file') {
  
  			// make way
  			$this->unlink($path2);
  
  			// copy
31b7f2792   Kload   Upgrade to ownclo...
442
443
444
  			if ($this->copy($path1, $path2) === false) {
  				return false;
  			}
03e52840d   Kload   Init
445

6d9380f96   Cédric Dupont   Update sources OC...
446
  			// cleanup
31b7f2792   Kload   Upgrade to ownclo...
447
448
449
450
  			if ($this->unlink($path1) === false) {
  				$this->unlink($path2);
  				return false;
  			}
03e52840d   Kload   Init
451

6d9380f96   Cédric Dupont   Update sources OC...
452
  			return true;
03e52840d   Kload   Init
453
  		}
6d9380f96   Cédric Dupont   Update sources OC...
454
  		return false;
03e52840d   Kload   Init
455
  	}
31b7f2792   Kload   Upgrade to ownclo...
456
457
  	public function getId() {
  		return $this->id;
03e52840d   Kload   Init
458
  	}
31b7f2792   Kload   Upgrade to ownclo...
459
460
  	public function getConnection() {
  		return $this->connection;
03e52840d   Kload   Init
461
  	}
31b7f2792   Kload   Upgrade to ownclo...
462
463
464
  	public function writeBack($tmpFile) {
  		if (!isset(self::$tmpFiles[$tmpFile])) {
  			return false;
03e52840d   Kload   Init
465
  		}
6d9380f96   Cédric Dupont   Update sources OC...
466
467
  		$fileData = fopen($tmpFile, 'r');
  		$this->container->uploadObject(self::$tmpFiles[$tmpFile], $fileData);
31b7f2792   Kload   Upgrade to ownclo...
468
  		unlink($tmpFile);
03e52840d   Kload   Init
469
  	}
6d9380f96   Cédric Dupont   Update sources OC...
470
471
472
473
474
475
476
477
478
479
480
  
  	/**
  	 * check if curl is installed
  	 */
  	public static function checkDependencies() {
  		if (function_exists('curl_init')) {
  			return true;
  		} else {
  			return array('curl');
  		}
  	}
03e52840d   Kload   Init
481
  }