Skip to content

Commit

Permalink
!!! TASK: Migrate to Flow 4.0 (#10)
Browse files Browse the repository at this point in the history
- Adjust to the renaming of the Resource namespace and class in Flow 4.0
- Adjusts code to package renaming from "TYPO3.Flow" to "Neos.Flow"
  • Loading branch information
johannessteu authored and kdambekalns committed Jan 30, 2017
1 parent 849b3c5 commit 38d16ff
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Classes/Command/S3CommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use Aws\S3\Model\ClearBucket;
use Aws\S3\S3Client;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;

/**
* S3 command controller for the Flownative.Aws.S3 package
Expand Down
48 changes: 24 additions & 24 deletions Classes/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* */

use Aws\S3\S3Client;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Resource\CollectionInterface;
use TYPO3\Flow\Resource\Resource;
use TYPO3\Flow\Resource\ResourceManager;
use TYPO3\Flow\Resource\ResourceRepository;
use TYPO3\Flow\Resource\Storage\Exception;
use TYPO3\Flow\Resource\Storage\Object;
use TYPO3\Flow\Resource\Storage\WritableStorageInterface;
use TYPO3\Flow\Utility\Environment;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\ResourceManagement\CollectionInterface;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\ResourceManagement\ResourceRepository;
use Neos\Flow\ResourceManagement\Storage\Exception;
use Neos\Flow\ResourceManagement\Storage\StorageObject;
use Neos\Flow\ResourceManagement\Storage\WritableStorageInterface;
use Neos\Flow\Utility\Environment;

/**
* A resource storage based on AWS S3
Expand Down Expand Up @@ -74,7 +74,7 @@ class S3Storage implements WritableStorageInterface

/**
* @Flow\Inject
* @var \TYPO3\Flow\Log\SystemLoggerInterface
* @var \Neos\Flow\Log\SystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -156,8 +156,8 @@ public function getKeyPrefix()
*
* @param string | resource $source The URI (or local path and filename) or the PHP resource stream to import the resource from
* @param string $collectionName Name of the collection the new Resource belongs to
* @return Resource A resource object representing the imported resource
* @throws \TYPO3\Flow\Resource\Storage\Exception
* @return PersistentResource A resource object representing the imported resource
* @throws \Neos\Flow\ResourceManagement\Storage\Exception
*/
public function importResource($source, $collectionName)
{
Expand Down Expand Up @@ -192,9 +192,9 @@ public function importResource($source, $collectionName)
* important because the resource management will derive the IANA Media Type from it.
*
* @param string $content The actual content to import
* @return Resource A resource object representing the imported resource
* @return PersistentResource A resource object representing the imported resource
* @param string $collectionName Name of the collection the new Resource belongs to
* @return Resource A resource object representing the imported resource
* @return PersistentResource A resource object representing the imported resource
* @throws Exception
* @api
*/
Expand All @@ -204,7 +204,7 @@ public function importResourceFromContent($content, $collectionName)
$md5Hash = md5($content);
$filename = $sha1Hash;

$resource = new Resource();
$resource = new PersistentResource();
$resource->setFilename($filename);
$resource->setFileSize(strlen($content));
$resource->setCollectionName($collectionName);
Expand Down Expand Up @@ -253,7 +253,7 @@ public function importUploadedResource(array $uploadInfo, $collectionName)
$sha1Hash = sha1_file($newSourcePathAndFilename);
$md5Hash = md5_file($newSourcePathAndFilename);

$resource = new Resource();
$resource = new PersistentResource();
$resource->setFilename($originalFilename);
$resource->setCollectionName($collectionName);
$resource->setFileSize(filesize($newSourcePathAndFilename));
Expand All @@ -274,11 +274,11 @@ public function importUploadedResource(array $uploadInfo, $collectionName)
/**
* Deletes the storage data related to the given Resource object
*
* @param \TYPO3\Flow\Resource\Resource $resource The Resource to delete the storage data of
* @param \Neos\Flow\ResourceManagement\PersistentResource $resource The Resource to delete the storage data of
* @return boolean TRUE if removal was successful
* @api
*/
public function deleteResource(Resource $resource)
public function deleteResource(PersistentResource $resource)
{
$this->s3Client->deleteObject(array(
'Bucket' => $this->bucketName,
Expand All @@ -291,11 +291,11 @@ public function deleteResource(Resource $resource)
* Returns a stream handle which can be used internally to open / copy the given resource
* stored in this storage.
*
* @param \TYPO3\Flow\Resource\Resource $resource The resource stored in this storage
* @param \Neos\Flow\ResourceManagement\PersistentResource $resource The resource stored in this storage
* @return resource | boolean A URI (for example the full path and filename) leading to the resource file or FALSE if it does not exist
* @api
*/
public function getStreamByResource(Resource $resource)
public function getStreamByResource(PersistentResource $resource)
{
try {
return fopen('s3://' . $this->bucketName . '/' . $this->keyPrefix . $resource->getSha1(), 'r');
Expand Down Expand Up @@ -334,7 +334,7 @@ public function getStreamByResourcePath($relativePath)
/**
* Retrieve all Objects stored in this storage.
*
* @return array<\TYPO3\Flow\Resource\Storage\Object>
* @return array<\Neos\Flow\ResourceManagement\Storage\StorageObject>
* @api
*/
public function getObjects()
Expand All @@ -351,7 +351,7 @@ public function getObjects()
*
* @param CollectionInterface $collection
* @internal param string $collectionName
* @return array<\TYPO3\Flow\Resource\Storage\Object>
* @return array<\Neos\Flow\ResourceManagement\Storage\StorageObject>
* @api
*/
public function getObjectsByCollection(CollectionInterface $collection)
Expand All @@ -361,7 +361,7 @@ public function getObjectsByCollection(CollectionInterface $collection)
$bucketName = $this->bucketName;

foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) {
/** @var \TYPO3\Flow\Resource\Resource $resource */
/** @var \Neos\Flow\ResourceManagement\PersistentResource $resource */
$object = new Object();
$object->setFilename($resource->getFilename());
$object->setSha1($resource->getSha1());
Expand All @@ -384,7 +384,7 @@ protected function importTemporaryFile($temporaryPathAndFilename, $collectionNam
$sha1Hash = sha1_file($temporaryPathAndFilename);
$md5Hash = md5_file($temporaryPathAndFilename);

$resource = new Resource();
$resource = new PersistentResource();
$resource->setFileSize(filesize($temporaryPathAndFilename));
$resource->setCollectionName($collectionName);
$resource->setSha1($sha1Hash);
Expand Down
36 changes: 18 additions & 18 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Resource\CollectionInterface;
use TYPO3\Flow\Resource\Exception;
use TYPO3\Flow\Resource\Resource;
use TYPO3\Flow\Resource\ResourceManager;
use TYPO3\Flow\Resource\ResourceMetaDataInterface;
use TYPO3\Flow\Resource\Target\TargetInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\ResourceManagement\CollectionInterface;
use Neos\Flow\ResourceManagement\Exception;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\ResourceManagement\ResourceMetaDataInterface;
use Neos\Flow\ResourceManagement\Target\TargetInterface;

/**
* A resource publishing target based on Amazon S3
Expand Down Expand Up @@ -57,7 +57,7 @@ class S3Target implements TargetInterface
/**
* Internal cache for known storages, indexed by storage name
*
* @var array<\TYPO3\Flow\Resource\Storage\StorageInterface>
* @var array<\Neos\Flow\ResourceManagement\Storage\StorageInterface>
*/
protected $storages = array();

Expand All @@ -74,7 +74,7 @@ class S3Target implements TargetInterface

/**
* @Flow\Inject
* @var \TYPO3\Flow\Log\SystemLoggerInterface
* @var \Neos\Flow\Log\SystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -157,7 +157,7 @@ public function getKeyPrefix()
/**
* Publishes the whole collection to this target
*
* @param \TYPO3\Flow\Resource\CollectionInterface $collection The collection to publish
* @param \Neos\Flow\ResourceManagement\CollectionInterface $collection The collection to publish
* @return void
* @throws Exception
*/
Expand Down Expand Up @@ -189,7 +189,7 @@ public function publishCollection(CollectionInterface $collection)
throw new Exception(sprintf('Could not publish collection %s because the source and target S3 bucket is the same, with identical key prefixes. Either choose a different bucket or at least key prefix for the target.', $collection->getName()), 1428929137);
}
foreach ($collection->getObjects() as $object) {
/** @var \TYPO3\Flow\Resource\Storage\Object $object */
/** @var \Neos\Flow\ResourceManagement\Storage\StorageObject $object */
$objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($object);
$options = array(
'ACL' => 'public-read',
Expand All @@ -209,7 +209,7 @@ public function publishCollection(CollectionInterface $collection)
}
} else {
foreach ($collection->getObjects() as $object) {
/** @var \TYPO3\Flow\Resource\Storage\Object $object */
/** @var \Neos\Flow\ResourceManagement\Storage\StorageObject $object */
$this->publishFile($object->getStream(), $this->getRelativePublicationPathAndFilename($object), $object);
unset($obsoleteObjects[$this->getRelativePublicationPathAndFilename($object)]);
}
Expand Down Expand Up @@ -237,12 +237,12 @@ public function getPublicStaticResourceUri($relativePathAndFilename)
/**
* Publishes the given persistent resource from the given storage
*
* @param \TYPO3\Flow\Resource\Resource $resource The resource to publish
* @param \Neos\Flow\ResourceManagement\PersistentResource $resource The resource to publish
* @param CollectionInterface $collection The collection the given resource belongs to
* @return void
* @throws Exception
*/
public function publishResource(Resource $resource, CollectionInterface $collection)
public function publishResource(PersistentResource $resource, CollectionInterface $collection)
{
$storage = $collection->getStorage();
if ($storage instanceof S3Storage) {
Expand Down Expand Up @@ -277,10 +277,10 @@ public function publishResource(Resource $resource, CollectionInterface $collect
/**
* Unpublishes the given persistent resource
*
* @param \TYPO3\Flow\Resource\Resource $resource The resource to unpublish
* @param \Neos\Flow\ResourceManagement\PersistentResource $resource The resource to unpublish
* @return void
*/
public function unpublishResource(Resource $resource)
public function unpublishResource(PersistentResource $resource)
{
try {
$objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource);
Expand All @@ -296,11 +296,11 @@ public function unpublishResource(Resource $resource)
/**
* Returns the web accessible URI pointing to the specified persistent resource
*
* @param \TYPO3\Flow\Resource\Resource $resource Resource object or the resource hash of the resource
* @param \Neos\Flow\ResourceManagement\PersistentResource $resource Resource object or the resource hash of the resource
* @return string The URI
* @throws Exception
*/
public function getPublicPersistentResourceUri(Resource $resource)
public function getPublicPersistentResourceUri(PersistentResource $resource)
{
if ($this->baseUri != '') {
return $this->baseUri . $this->getRelativePublicationPathAndFilename($resource);
Expand Down
79 changes: 57 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
{
"name": "flownative/aws-s3",
"type": "typo3-flow-package",
"description": "Amazon S3 adaptor for Neos and Flow",
"authors": [
{
"name": "Robert Lemke",
"email": "[email protected]",
"homepage": "https://www.flownative.com",
"role": "Developer"
"name": "flownative/aws-s3",
"type": "neos-package",
"description": "",
"authors": [
{
"name": "Robert Lemke",
"email": "[email protected]",
"homepage": "https://www.flownative.com",
"role": "Developer"
}
],
"license": [
"MIT"
],
"require": {
"neos/flow": "~4.0",
"aws/aws-sdk-php": "2.8.*"
},
"autoload": {
"psr-4": {
"Flownative\\Aws\\S3\\": "Classes"
}
},
"extra": {
"applied-flow-migrations": [
"TYPO3.FLOW3-201201261636",
"TYPO3.Fluid-201205031303",
"TYPO3.FLOW3-201205292145",
"TYPO3.FLOW3-201206271128",
"TYPO3.FLOW3-201209201112",
"TYPO3.Flow-201209251426",
"TYPO3.Flow-201211151101",
"TYPO3.Flow-201212051340",
"TYPO3.Flow-201310031523",
"TYPO3.Flow-201405111147",
"TYPO3.Fluid-20141113120800",
"TYPO3.Flow-20141113121400",
"TYPO3.Fluid-20141121091700",
"TYPO3.Fluid-20150214130800",
"TYPO3.Flow-20151113161300",
"TYPO3.Form-20160601101500",
"TYPO3.Flow-20161115140400",
"TYPO3.Flow-20161115140430",
"Neos.Flow-20161124204700",
"Neos.Flow-20161124204701",
"Neos.Twitter.Bootstrap-20161124204912",
"Neos.Form-20161124205254",
"Neos.Flow-20161124224015",
"Neos.Party-20161124225257",
"Neos.Eel-20161124230101",
"Neos.Imagine-20161124231742",
"Neos.Media-20161124233100",
"Neos.Flow-20161125124112",
"Neos.SwiftMailer-20161130105617",
"TYPO3.FluidAdaptor-20161130112935",
"Neos.Media-20161219094126"
]
}
],
"license": [
"MIT"
],
"require": {
"typo3/flow": "~3.1",
"aws/aws-sdk-php": "2.8.*"
},
"autoload": {
"psr-4": {
"Flownative\\Aws\\S3\\": "Classes"
}
}
}

0 comments on commit 38d16ff

Please sign in to comment.