Skip to content

Typo3 12 compatibility #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions .github/workflows/autopublish-to-ter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
# Controls when the action will run. Triggers the workflow on tags
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
tags:
- '**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down Expand Up @@ -38,38 +36,19 @@ jobs:
name: TYPO3 TER release

# Depend on a valid tag
#needs: tag-valid
#if: needs.tag-valid.outputs.status == 'true'
needs: tag-valid
if: needs.tag-valid.outputs.status == 'true'

runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [7.4]

env:
# Add your extension key
TYPO3_EXTENSION_KEY: google_cloud_storage_fal
TYPO3_USER: ${{ secrets.TYPO3_USER }}
TYPO3_PASSWORD: ${{ secrets.TYPO3_PASSWORD }}
fail-fast: false

steps:
- uses: actions/checkout@v2
with:
path: ${{ env.TYPO3_EXTENSION_KEY }}
- name: Checkout
uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
- name: Publish to TER
uses: tomasnorre/typo3-upload-ter@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: intl, mbstring, xml, soap, zip, curl

- name: Install TYPO3 TER client
run: composer global require namelesscoder/typo3-repository-client "^2.0" --prefer-dist --no-progress --no-suggest

- name: Remove .git folder
run: rm -rf ./$TYPO3_EXTENSION_KEY/.git

- name: Remove .github folder
run: rm -rf ./$TYPO3_EXTENSION_KEY/.github
api-token: ${{ secrets.TYPO3_API_TOKEN }}

- name: Upload EXT:${{ env.TYPO3_EXTENSION_KEY }} as ${{ github.event.ref }} to TER
run: php ~/.composer/vendor/bin/upload "./$TYPO3_EXTENSION_KEY" "$TYPO3_USER" "$TYPO3_PASSWORD" "${{ github.event.head_commit.message }}"
30 changes: 17 additions & 13 deletions Classes/Bucket/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use Google\Cloud\Storage\Bucket;
use Google\Cloud\Storage\StorageObject;
use Nextmotion\GoogleCloudStorageDriver\Cache\BucketCache;

/**
Expand All @@ -24,19 +25,19 @@ class Operations
/**
* @var Bucket
*/
private $bucket;
private Bucket $bucket;
/**
* @var Objects
*/
private $bucketObjects;
private Objects $bucketObjects;
/**
* @var BucketCache
*/
private $bucketCache;
private mixed $bucketCache;
/**
* @var NamingHelper
*/
private $namingHelper;
private NamingHelper $namingHelper;

/**
* Operations constructor.
Expand All @@ -59,7 +60,7 @@ public function __construct(Bucket $bucket, NamingHelper $namingHelper, Objects
*
* @return bool
*/
public function mkdir($folderName)
public function mkdir(string $folderName): bool
{
$folderName = $this->namingHelper->normalizeFolderName($folderName);
// Bucket root exists by default
Expand All @@ -79,9 +80,9 @@ public function mkdir($folderName)
*
* @param string $filename
*
* @return \Google\Cloud\Storage\StorageObject
* @return StorageObject
*/
public function createEmptyFile($filename)
public function createEmptyFile(string $filename): StorageObject
{
if ($this->bucketCache instanceof BucketCache) {
$this->bucketCache->clear();
Expand All @@ -96,15 +97,18 @@ public function createEmptyFile($filename)
* @param string $fileIdentifier
* @param string $targetFileName
*
* @return \Google\Cloud\Storage\StorageObject
* @return StorageObject
*/
public function copyFromTo($fileIdentifier, $targetFileName)
public function copyFromTo(string $fileIdentifier, string $targetFileName): StorageObject
{
if ($this->bucketCache instanceof BucketCache) {
$this->bucketCache->clear();
}

return $this->bucket->object($fileIdentifier)->copy($this->bucket->name(), ['name' => $targetFileName]);
$fileIdentifier = ltrim($fileIdentifier, '/');
$file = $this->bucket->object($fileIdentifier);
$bucketName = $this->bucket->name();
return $file->copy($bucketName, ['name' => $targetFileName]);
}

/**
Expand All @@ -113,9 +117,9 @@ public function copyFromTo($fileIdentifier, $targetFileName)
* @param string $oldName
* @param string $newName
*
* @return \Google\Cloud\Storage\StorageObject|null
* @return StorageObject|null
*/
public function rename($oldName, $newName)
public function rename(string $oldName, string $newName): ?StorageObject
{
if ($this->bucketCache instanceof BucketCache) {
$this->bucketCache->clear();
Expand All @@ -137,7 +141,7 @@ public function rename($oldName, $newName)
*
* @return void
*/
public function delete($fileIdentifier, $isFolder = false)
public function delete(string $fileIdentifier, bool $isFolder = false): void
{
if ($isFolder === true) {
$fileIdentifier = $this->namingHelper->normalizeFolderName($fileIdentifier);
Expand Down
43 changes: 25 additions & 18 deletions Classes/Bucket/SimpleBucketObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@

class SimpleBucketObject
{
const TYPE_FILE = 0;
const TYPE_FOLDER = 1;
public const TYPE_FILE = 0;
public const TYPE_FOLDER = 1;

/**
* @var string full path of file or folder
*/
private $name;
private string $name;

/**
* @var string Determinated content type by google
*/
private $contentType;
private string $contentType;

/**
* @var int Filesize in byte
*/
private $filesize;
private int $filesize;

/**
* @var int Timestamp
*/
private $created_at;
private int $created_at;

/**
* @var int Timestamp
*/
private $updated_at;
private int $updated_at;

/**
* @var int See TYPE_FILE OR TYPE_FOLDER
*/
private $type;
private int $type;

/**
* SimpleBucketObject constructor.
Expand All @@ -54,12 +54,19 @@ class SimpleBucketObject
*/
public function __construct($config)
{
$this->name = $config['name'];
$this->type = $config['type'];
$this->contentType = $config['contentType'] ?? 0;
$this->filesize = $config['filesize'] ?? 0;
$this->created_at = $config['created_at'] ?? 0;
$this->updated_at = $config['updated_at'] ?? 0;
$name = $config['name'] ?? '';
$type = $config['type'];
$contentType = $config['contentType'] ?? 0;
$filesize = $config['filesize'] ?? 0;
$created_at = $config['created_at'] ?? 0;
$updated_at = $config['updated_at'] ?? 0;

$this->name = (string)$name;
$this->type = (int) $type;
$this->contentType = (string)$contentType;
$this->filesize = (int)$filesize;
$this->created_at = (int)$created_at;
$this->updated_at = (int)$updated_at;
}

/**
Expand Down Expand Up @@ -134,16 +141,16 @@ public function toArray(): array
/**
* @return bool
*/
public function isFolder()
public function isFolder(): bool
{
return $this->type == self::TYPE_FOLDER;
return $this->type === self::TYPE_FOLDER;
}

/**
* @return bool
*/
public function isFile()
public function isFile(): bool
{
return $this->type == self::TYPE_FILE;
return $this->type === self::TYPE_FILE;
}
}
43 changes: 23 additions & 20 deletions Classes/Command/MoveFilesBetweenStorages.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,50 @@
class MoveFilesBetweenStorages extends Command
{

const WARNING = 'warning';
public const WARNING = 'warning';

/**
* @var SymfonyStyle
*/
protected $io;
protected SymfonyStyle $io;

/**
* @var array
*/
protected $options = [];
protected array $options = [];

/**
* @var ResourceStorage
*/
protected $sourceStorage;
protected ResourceStorage $sourceStorage;

/**
* @var ResourceStorage
*/
protected $targetStorage;
protected ResourceStorage $targetStorage;

/**
* @var array
*/
protected $missingFiles = [];
protected array $missingFiles = [];

/**
* @var string
*/
protected $tableName = 'sys_file';
protected string $tableName = 'sys_file';
/**
* @var array
*/
protected $hasFolders = [];
protected array $hasFolders = [];
/**
* @var array
*/
private $configuration = [];
private array $configuration = [];

/**
* Configure the command by defining the name, options and arguments
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription(
Expand Down Expand Up @@ -139,7 +139,7 @@ protected function configure()
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);

Expand All @@ -161,8 +161,9 @@ protected function initialize(InputInterface $input, OutputInterface $output)
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{

if ($this->targetStorage->getDriverType() !== "GoogleCloudStorageDriver") {
Expand Down Expand Up @@ -218,7 +219,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param array $arguments
* @param string $severity can be 'warning', 'error', 'success'
*/
protected function log(string $message = '', array $arguments = [], $severity = '')
protected function log(string $message = '', array $arguments = [], $severity = ''): void
{
$formattedMessage = vsprintf($message, $arguments);
if ($severity) {
Expand All @@ -228,7 +229,7 @@ protected function log(string $message = '', array $arguments = [], $severity =
}
}

private function transfer($sourceStorage, $targetStorage, \TYPO3\CMS\Core\Resource\Driver\AbstractDriver $sourceDriver, StorageDriver $targetDriver, $filter, $excludes, $limits)
private function transfer($sourceStorage, $targetStorage, \TYPO3\CMS\Core\Resource\Driver\AbstractDriver $sourceDriver, StorageDriver $targetDriver, $filter, $excludes, $limits): void
{

$files = $this->getFiles($sourceStorage, $filter, $excludes, $limits);
Expand Down Expand Up @@ -305,8 +306,10 @@ private function transfer($sourceStorage, $targetStorage, \TYPO3\CMS\Core\Resour
}

/**
* @param InputInterface $input
*
* @param $storage
* @param $filter
* @param $excludes
* @param $limits
* @return array
*/
protected function getFiles($storage, $filter, $excludes, $limits): array
Expand Down Expand Up @@ -490,9 +493,9 @@ protected function updateDatabase(File $fileObject, array $values): int
}

/**
* @return object|Connection
* @return \TYPO3\CMS\Core\Database\Connection
*/
protected function getConnection(): Connection
protected function getConnection(): \TYPO3\CMS\Core\Database\Connection
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
Expand All @@ -503,7 +506,7 @@ protected function getConnection(): Connection
* @param string $type
* @param array $files
*/
protected function writeLog(string $type, array $files)
protected function writeLog(string $type, array $files): void
{
$logFileName = sprintf(
'/tmp/%s-files-%s-%s-log',
Expand Down Expand Up @@ -531,7 +534,7 @@ protected function writeLog(string $type, array $files)
* @param string $message
* @param array $arguments
*/
protected function warning(string $message = '', array $arguments = [])
protected function warning(string $message = '', array $arguments = []): void
{
$this->log($message, $arguments, self::WARNING);
}
Expand Down
Loading