PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.22.4
JetBackup – Backup, Restore & Migrate v3.1.22.4
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Destination / Vendors / pCloud / DirIterator.php
backup / src / JetBackup / Destination / Vendors / pCloud Last commit date
Client 1 year ago .htaccess 1 year ago ChunkedDownload.php 1 year ago ChunkedUpload.php 1 year ago DirIterator.php 1 year ago index.html 1 year ago pCloud.php 1 year ago web.config 1 year ago
DirIterator.php
93 lines
1 <?php
2 /*
3 *
4 * JetBackup @ package
5 * Created By Idan Ben-Ezra
6 *
7 * Copyrights @ JetApps
8 * https://www.jetapps.com
9 *
10 **/
11 namespace JetBackup\Destination\Vendors\pCloud;
12
13 use Exception;
14 use JetBackup\Destination\DestinationFile;
15 use JetBackup\Destination\Integration\DestinationDirIterator;
16 use JetBackup\Destination\Integration\DestinationFile as iDestinationFile;
17 use JetBackup\Destination\Vendors\pCloud\Client\Client;
18 use JetBackup\Destination\Vendors\pCloud\Client\File;
19 use JetBackup\Exception\IOException;
20 use JetBackup\Exception\JBException;
21
22 defined( '__JETBACKUP__' ) or die( 'Restricted access' );
23
24 class DirIterator implements DestinationDirIterator {
25
26 private pCloud $_destination;
27 private string $_directory;
28 /** @var File[] */
29 private array $_files=[];
30
31 /**
32 * @param pCloud $destination
33 * @param string $directory
34 * @param string|null $parent_id
35 *
36 * @throws IOException
37 * @throws JBException
38 */
39 public function __construct(pCloud $destination, string $directory) {
40 $this->_destination = $destination;
41 $this->_directory = $directory;
42
43 if(!$this->_destination->getClient()) throw new IOException("Unable to retrieve google drive service");
44 //if(!$this->_destination->dirExists($this->_directory)) return;
45
46 $this->rewind();
47 }
48
49 /**
50 * @return void
51 * @throws IOException
52 */
53 public function rewind():void {
54 try {
55
56 $this->_files = $this->_destination->_retries(function() {
57 return $this->_destination->getClient()->listFolder($this->_directory);
58 }, "Failed fetching list of files");
59
60 } catch(Exception $e) {
61 if($e->getCode() == Client::CODE_DIR_NOT_FOUND) $this->_files = [];
62 else throw new IOException($e->getMessage(), $e->getCode(), $e);
63 }
64 }
65
66 /**
67 * @return bool
68 * @throws IOException
69 */
70 public function hasNext():bool { return ($this->_files && count($this->_files)); }
71
72 /**
73 * @return ?iDestinationFile
74 * @throws IOException
75 */
76 public function getNext():?iDestinationFile {
77 if(!$this->hasNext()) return null;
78
79 $nextfile = array_shift($this->_files);
80
81 $path = $this->_directory . '/' . $nextfile->getName();
82 $basename = basename($path);
83
84 $file = new DestinationFile();
85 $file->setType($nextfile->getMimeType() == Client::MIMITYPE_DIR ? iDestinationFile::TYPE_DIRECTORY : iDestinationFile::TYPE_FILE);
86 $file->setName($basename);
87 $file->setPath($basename == $path ? '' : dirname($path));
88 $file->setSize($nextfile->getMimeType() == Client::MIMITYPE_DIR ? 4096 : $nextfile->getSize());
89 $file->setModifyTime($nextfile->getModificationTime());
90
91 return $file;
92 }
93 }