2016-10-28 04:54:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\AlbumSources;
|
|
|
|
use App\Photo;
|
2016-10-28 06:24:34 +01:00
|
|
|
use OpenCloud\OpenStack;
|
2016-10-28 04:54:38 +01:00
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Driver for managing files on the local filesystem.
|
|
|
|
* @package App\AlbumSources
|
|
|
|
*/
|
|
|
|
class OpenStackSource extends AlbumSourceBase implements IAlbumSource
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Deletes an entire album's media contents.
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function deleteAlbumContents()
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
|
|
|
// TODO: Implement deleteAlbumContents() method.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a thumbnail file for a photo.
|
|
|
|
* @param Photo $photo Photo to delete the thumbnail from.
|
|
|
|
* @param string $thumbnail Thumbnail to delete (or null to delete the original.)
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function deleteThumbnail(Photo $photo, $thumbnail = null)
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
|
|
|
// TODO: Implement deleteThumbnail() method.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the name of this album source.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function getName()
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
|
|
|
return 'global.album_sources.openstack';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the absolute path to the given photo file.
|
|
|
|
* @param Photo $photo Photo to get the path to.
|
|
|
|
* @param string $thumbnail Thumbnail to get the image to.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function getPathToPhoto(Photo $photo, $thumbnail = null)
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
|
|
|
// TODO: Implement getPathToPhoto() method.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the absolute URL to the given photo file.
|
|
|
|
* @param Photo $photo Photo to get the URL to.
|
|
|
|
* @param string $thumbnail Thumbnail to get the image to.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function getUrlToPhoto(Photo $photo, $thumbnail = null)
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
2016-10-28 06:24:34 +01:00
|
|
|
return sprintf(
|
|
|
|
'%s/%s/%s/%s',
|
|
|
|
'https://photos-dev-898b0644.cdn.memsites.com',
|
|
|
|
$this->album->url_alias,
|
|
|
|
is_null($thumbnail) ? $this->getOriginalsFolder() : $thumbnail,
|
|
|
|
$photo->storage_file_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveOriginal(Photo $photo, $tempFilename)
|
|
|
|
{
|
|
|
|
$this->saveThumbnail($photo, $tempFilename, $this->getOriginalsFolder());
|
2016-10-28 04:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves a generated thumbnail to its permanent location.
|
|
|
|
* @param Photo $photo Photo the thumbnail relates to.
|
|
|
|
* @param string $tempFilename Filename containing the thumbnail.
|
2016-10-28 06:24:34 +01:00
|
|
|
* @param string $thumbnail Name of the thumbnail.
|
2016-10-28 04:54:38 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function saveThumbnail(Photo $photo, $tempFilename, $thumbnail)
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
2016-10-28 06:24:34 +01:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$container->uploadObject(
|
|
|
|
sprintf('%s/%s/%s', $this->album->url_alias, $thumbnail, $photo->storage_file_name),
|
|
|
|
fopen($tempFilename, 'r+')
|
|
|
|
);
|
2016-10-28 04:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves an uploaded file to the container and returns the filename.
|
|
|
|
* @param File $uploadedFile The photo uploaded
|
|
|
|
* @param string $overrideFilename Specific file name to use, or null to randomly generate one.
|
|
|
|
* @return File
|
|
|
|
*/
|
2016-10-28 06:24:34 +01:00
|
|
|
public function saveUploadedPhoto(File $uploadedFile, $overrideFilename = null)
|
2016-10-28 04:54:38 +01:00
|
|
|
{
|
|
|
|
// TODO: Implement saveUploadedPhoto() method.
|
|
|
|
}
|
2016-10-28 06:24:34 +01:00
|
|
|
|
|
|
|
private function getClient()
|
|
|
|
{
|
|
|
|
return new OpenStack($this->configuration->auth_url, [
|
|
|
|
'username' => $this->configuration->username,
|
|
|
|
'password' => decrypt($this->configuration->password),
|
|
|
|
'tenantName' => $this->configuration->tenant_name,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getContainer()
|
|
|
|
{
|
|
|
|
return $this->getStorageService()->getContainer($this->configuration->container_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getOriginalsFolder()
|
|
|
|
{
|
|
|
|
return '_originals';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStorageService()
|
|
|
|
{
|
|
|
|
return $this->getClient()->objectStoreService(
|
|
|
|
$this->configuration->service_name,
|
|
|
|
$this->configuration->service_region,
|
|
|
|
'publicURL'
|
|
|
|
);
|
|
|
|
}
|
2016-10-28 04:54:38 +01:00
|
|
|
}
|