/** * {@inheritDoc} */ public function remove(array $paths, array $filters) { if (empty($paths) && empty($filters)) { return; } if (empty($paths)) { try { $this->storage->deleteMatchingObjects($this->bucket, null, sprintf('/%s/i', implode('|', $filters))); } catch (\Exception $e) { $this->logError('The objects could not be deleted from Amazon S3.', array('filter' => implode(', ', $filters), 'bucket' => $this->bucket, 'exception' => $e)); } return; } foreach ($filters as $filter) { foreach ($paths as $path) { $objectPath = $this->getObjectPath($path, $filter); if (!$this->objectExists($objectPath)) { continue; } try { $this->storage->deleteObject(array('Bucket' => $this->bucket, 'Key' => $objectPath)); } catch (\Exception $e) { $this->logError('The object could not be deleted from Amazon S3.', array('objectPath' => $objectPath, 'filter' => $filter, 'bucket' => $this->bucket, 'exception' => $e)); } } } }
/** * Delete a directory. * * @param string $dirname * * @return bool */ public function deleteDir($dirname) { try { $prefix = $this->applyPathPrefix($dirname) . '/'; $this->s3Client->deleteMatchingObjects($this->bucket, $prefix); } catch (DeleteMultipleObjectsException $exception) { return false; } return true; }
/** * Delete Folder * * @param string $folder Path folder * * @return bool * @throws */ public function deleteFolder($folder) { $folder = trim($folder, '/') . '/'; // Fail if this pseudo directory key already exists if (!$this->isDir($folder)) { $path = $this->bucket . "/" . $folder; throw new ExceptionStorage("Directory {$path} Not found or Not Is Diretory", static::E_NOT_IS_DIR); } return (bool) $this->clientS3->deleteMatchingObjects($this->bucket, $folder); }
/** * Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you * to do things like delete all objects that match a specific key prefix. * * @param string $bucket Bucket that contains the object keys * @param string $prefix Optionally delete only objects under this key prefix * @param string $regex Delete only objects that match this regex * @param array $options Options used when deleting the object: * - before_delete: Callback to invoke before each delete. The callback will receive a * Guzzle\Common\Event object with context. * * @see Aws\S3\S3Client::listObjects * @see Aws\S3\Model\ClearBucket For more options or customization * @return int Returns the number of deleted keys * @throws \RuntimeException if no prefix and no regex is given */ public function deleteMatchingObjects($bucket, $prefix = '', $regex = '', array $options = []) { return $this->instance->deleteMatchingObjects($bucket, $prefix, $regex, $options); }
/** * Delete a directory (recursive) * * @param string $path * @return boolean delete result */ public function deleteDir($path) { return $this->client->deleteMatchingObjects($this->bucket, $this->prefix($path)); }
/** * deleteMatchingObjects * * @param string $prefix * @param string $regex * @param array $options * * @return integer */ public function deleteMatchingObjects($prefix = '', $regex = '', array $options = array()) { return $this->client->deleteMatchingObjects($this->name, $prefix, $regex, $options); }
/** * Delete a directory (recursive) * * @param string $path * @return boolean delete result */ public function deleteDir($path) { $prefix = rtrim($this->prefix($path), '/') . '/'; return $this->client->deleteMatchingObjects($this->bucket, $prefix); }