Skip to content

Commit

Permalink
Merge pull request #30 from erikn69/1.x
Browse files Browse the repository at this point in the history
[1.x] Uncache folders, get drive service, empty trash
  • Loading branch information
masbug authored Jul 19, 2021
2 parents aa0b678 + 16388d6 commit da184d9
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ public function __construct(Google_Service_Drive $service, $root = null, $option
}
}

/**
* Gets the service (Google_Service_Drive)
*
* @return object Google_Service_Drive
*/
public function getService()
{
return $this->service;
}

/**
* Allow to forcefully clear the cache to enable long running process
*
Expand Down Expand Up @@ -478,7 +488,7 @@ protected function delete_by_id($ids)
}
foreach ($ids as $id) {
if ($id !== '' && ($file = $this->getFileObject($id))) {
if (($parents = $file->getParents())) {
if ($file->getParents()) {
$file = new Google_Service_Drive_DriveFile();
$file->setTrashed(true);
if ($this->service->files->update($id, $file, $this->applyDefaultParams([], 'files.update'))) {
Expand Down Expand Up @@ -1543,8 +1553,27 @@ protected function buildPathFromCacheFileObjects($lastItemId)
return $complete_paths;
}

public function uncacheFolder($path)
{
if ($this->useDisplayPaths) {
try {
$path_id = $this->getCachedPathId($path);
if (is_array($path_id) && !empty($path_id[0] ?? null)) {
$this->uncacheId($path_id[0]);
}
} catch (FileNotFoundException $e) {
// unnecesary
}
} else {
$this->uncacheId($path);
}
}

protected function uncacheId($id)
{
if (empty($id)) {
return;
}
$basePath = null;
foreach ($this->cachedPaths as $path => $itemId) {
if ($itemId === $id) {
Expand Down Expand Up @@ -2015,6 +2044,19 @@ protected function applyDefaultParams($params, $cmdName)
}
}

/**
* Enables empty google drive trash
*
* @return void
*
* @see https://developers.google.com/drive/v3/reference/files emptyTrash
* @see \Google_Service_Drive_Resource_Files
*/
public function emptyTrash(array $params = [])
{
$this->service->files->emptyTrash($this->applyDefaultParams($params, 'files.emptyTrash'));
}

/**
* Enables Team Drive support by changing default parameters
*
Expand Down

0 comments on commit da184d9

Please sign in to comment.