Skip to content
Snippets Groups Projects
Commit 3c409c30 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Issue #3256578 by retiredpro, Aporie, volman, hatuhay, vadim s. sabinich,...

Issue #3256578 by retiredpro, Aporie, volman, hatuhay, vadim s. sabinich, semiaddict, Schoenef, arturopanetta: Incompatible with newest version of the php-ffmpeg (v0.19.0) package
parent 729c340f
Branches
Tags
1 merge request!6Resolve #3256578 "Cache d10"
Pipeline #67438 passed with warnings
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
# variables:
# SKIP_ESLINT: '1'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
{
"name": "drupal/php-ffmpeg",
"name": "drupal/php_ffmpeg",
"type": "drupal-module",
"description": "Drupal library module for PHP-FFMpeg.",
"homepage": "http://drupal.org/project/php_ffmpeg",
......@@ -15,7 +15,7 @@
"issues": "http://drupal.org/project/issues/php_ffmpeg"
},
"require": {
"drupal/core": "^8.0 | ^9.0",
"php-ffmpeg/php-ffmpeg": "*"
"drupal/core": "^9.1 || ^10",
"php-ffmpeg/php-ffmpeg": "^0.19 | ^1.1"
}
}
......@@ -2,6 +2,5 @@ name: PHP-FFMpeg
description: 'Integrates with the PHP FFmpeg library.'
type: module
package: Development
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.1 || ^10
configure: php_ffmpeg.settings
......@@ -2,13 +2,13 @@
namespace Drupal\php_ffmpeg;
use Doctrine\Common\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
/**
* Adapter between Doctrine cache needed by FFMPeg library and Drupal cache.
* Adapter between Symfony cache needed by FFMPeg library and Drupal cache.
*/
class PHPFFMpegCache implements Cache {
class PHPFFMpegCache extends AbstractAdapter {
/**
* The cache backend that should be used.
......@@ -17,13 +17,6 @@ class PHPFFMpegCache implements Cache {
*/
protected $cache;
/**
* Prefix for the cache ids.
*
* @var string
*/
protected $prefix;
/**
* Constructs a CacheCollector object.
*
......@@ -33,61 +26,56 @@ class PHPFFMpegCache implements Cache {
* Prefix used for appending to cached item identifiers.
*/
public function __construct(CacheBackendInterface $cache, $prefix) {
parent::__construct($prefix);
$this->cache = $cache;
$this->prefix = (string) $prefix;
}
/**
* {@inheritdoc}
*/
public function fetch($id) {
if ($cache = $this->cache->get($this->getCid($id))) {
return $cache->data;
}
return FALSE;
protected function doFetch(array $ids): iterable {
$items = $this->cache->getMultiple($ids);
array_walk($items, function (&$item) {
$item = $item->data;
});
return $items;
}
/**
* {@inheritdoc}
*/
public function contains($id) {
return (bool) $this->fetch($id);
protected function doHave(string $id): bool {
return ($this->cache->get($id) !== FALSE);
}
/**
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = 0) {
$this->cache->set($this->getCid($id), $data, time() + $lifeTime);
protected function doSave(array $values, int $lifetime): array|bool {
array_walk($values, function (&$value) use ($lifetime) {
$value = [
"data" => $value,
"expire" => ($lifetime == 0) ? CacheBackendInterface::CACHE_PERMANENT : time() + $lifetime
];
});
$this->cache->setMultiple($values);
return TRUE;
}
/**
* {@inheritdoc}
*/
public function delete($id) {
$this->cache->delete($this->getCid($id));
protected function doDelete(array $ids): bool {
$this->cache->deleteMultiple($ids);
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getStats() {
return NULL;
}
/**
* Returns a prefixed cache id based on given id.
*
* @param string $id
* The id string to prefix.
*
* @return string
* A prefixed cache id.
*/
protected function getCid($id) {
return "{$this->prefix}:{$id}";
protected function doClear(string $namespace): bool {
$this->cache->deleteAll();
return TRUE;
}
}
......@@ -4,7 +4,7 @@ namespace Drupal\php_ffmpeg;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Doctrine\Common\Cache\Cache;
use Psr\Cache\CacheItemPoolInterface;
use FFMpeg\FFMpeg;
use FFMpeg\FFProbe;
......@@ -16,7 +16,7 @@ class PHPFFMpegFactory {
/**
* The cache backend that should be passed to the FFMpeg extension.
*
* @var \Doctrine\Common\Cache\Cache
* @var \Psr\Cache\CacheItemPoolInterface
*/
protected $cache;
......@@ -38,14 +38,14 @@ class PHPFFMpegFactory {
/**
* Constructs a the factory object with injected dependencies.
*
* @param \Doctrine\Common\Cache\Cache $cache
* @param \Psr\Cache\CacheItemPoolInterface $cache
* The cache backend.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* Prefix used for appending to cached item identifiers.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A configuration factory instance.
*/
public function __construct(Cache $cache, LoggerChannelInterface $logger, ConfigFactoryInterface $config_factory) {
public function __construct(CacheItemPoolInterface $cache, LoggerChannelInterface $logger, ConfigFactoryInterface $config_factory) {
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config_factory->getEditable('php_ffmpeg.settings');
......
......@@ -30,7 +30,7 @@ class PHPFFMpegTestCase extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['php_ffmpeg'];
protected static $modules = ['php_ffmpeg'];
/**
* The Drupal FS.
......@@ -42,7 +42,7 @@ class PHPFFMpegTestCase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->fileSystem = $this->container->get('file_system');
......@@ -69,17 +69,17 @@ class PHPFFMpegTestCase extends BrowserTestBase {
$this->drupalLogin($account);
$this->drupalGet('admin/config/development/php-ffmpeg');
$this->assertFieldByName('ffmpeg_binary', $ffmpeg_binary, 'The PHP-FFMpeg settings page should provide a field for the ffmpeg binary path.');
$this->assertFieldByName('ffprobe_binary', $ffprobe_binary, 'The PHP-FFMpeg settings page should provide a field for the ffprobe binary path.');
$this->assertFieldByName('execution_timeout', $execution_timeout, 'The PHP-FFMpeg settings page should provide a field for the ffmpeg command timeout.');
$this->assertFieldByName('threads_amount', $threads_amount, 'The PHP-FFMpeg settings page should provide a field for the number of threads to use for ffmpeg commands.');
$this->assertSession()->fieldValueEquals('ffmpeg_binary', $ffmpeg_binary);
$this->assertSession()->fieldValueEquals('ffprobe_binary', $ffprobe_binary);
$this->assertSession()->fieldValueEquals('execution_timeout', $execution_timeout);
$this->assertSession()->fieldValueEquals('threads_amount', $threads_amount);
$ffmpeg_binary = $this->fileSystem->realpath($this->drupalGetTestFiles('binary')[0]->uri);
$ffprobe_binary = $this->fileSystem->realpath($this->drupalGetTestFiles('binary')[1]->uri);
$execution_timeout = mt_rand(1, 42);
$threads_amount = mt_rand(1, 42);
$this->drupalPostForm(NULL, [
$this->submitForm([
'ffmpeg_binary' => $ffmpeg_binary,
'ffprobe_binary' => $ffprobe_binary,
'execution_timeout' => $execution_timeout,
......@@ -87,22 +87,22 @@ class PHPFFMpegTestCase extends BrowserTestBase {
], 'Save configuration');
$settings = $this->config('php_ffmpeg.settings');
$this->assertFieldByName('ffmpeg_binary', $ffmpeg_binary, 'Submitting he PHP-FFMpeg settings page should update the value of the field for the ffmpeg binary path.');
$this->assertFieldByName('ffprobe_binary', $ffprobe_binary, 'Submitting he PHP-FFMpeg settings page should update the value of the field for the ffprobe binary path.');
$this->assertFieldByName('execution_timeout', $execution_timeout, 'Submitting he PHP-FFMpeg settings page should update the value of the field for the ffmpeg command timeout.');
$this->assertFieldByName('threads_amount', $threads_amount, 'Submitting he PHP-FFMpeg settings page should update the value of the field for the number of threads to use for ffmpeg commands.');
$this->assertSession()->fieldValueEquals('ffmpeg_binary', $ffmpeg_binary);
$this->assertSession()->fieldValueEquals('ffprobe_binary', $ffprobe_binary);
$this->assertSession()->fieldValueEquals('execution_timeout', $execution_timeout);
$this->assertSession()->fieldValueEquals('threads_amount', $threads_amount);
$this->assertEqual($settings->get('ffmpeg_binary'), $ffmpeg_binary, 'Submitting he PHP-FFMpeg settings page should update the ffmpeg binary path.');
$this->assertEqual($settings->get('ffprobe_binary'), $ffprobe_binary, 'Submitting he PHP-FFMpeg settings page should update the ffproe binary path.');
$this->assertEqual($settings->get('execution_timeout'), $execution_timeout, 'Submitting he PHP-FFMpeg settings page should update the ffmpeg command timeout.');
$this->assertEqual($settings->get('threads_amount'), $threads_amount, 'Submitting he PHP-FFMpeg settings page should update the number of threads to use for ffmpeg commands.');
$this->assertEquals($settings->get('ffmpeg_binary'), $ffmpeg_binary, 'Submitting he PHP-FFMpeg settings page should update the ffmpeg binary path.');
$this->assertEquals($settings->get('ffprobe_binary'), $ffprobe_binary, 'Submitting he PHP-FFMpeg settings page should update the ffproe binary path.');
$this->assertEquals($settings->get('execution_timeout'), $execution_timeout, 'Submitting he PHP-FFMpeg settings page should update the ffmpeg command timeout.');
$this->assertEquals($settings->get('threads_amount'), $threads_amount, 'Submitting he PHP-FFMpeg settings page should update the number of threads to use for ffmpeg commands.');
$invalidFilenames = [
$this->randomMachineName(),
$this->randomMachineName(),
];
$this->drupalPostForm(NULL, [
$this->submitForm([
'ffmpeg_binary' => $invalidFilenames[0],
'ffprobe_binary' => $invalidFilenames[1],
'execution_timeout' => $this->randomString(),
......@@ -110,12 +110,12 @@ class PHPFFMpegTestCase extends BrowserTestBase {
], 'Save configuration');
$settings = $this->config('php_ffmpeg.settings');
$this->assertText("File not found: $invalidFilenames[0]", "Submission of the the PHP-FFMpeg settings page should validate the ffmpeg binary path is an existing file.");
$this->assertText("File not found: $invalidFilenames[1]", "Submission of the the PHP-FFMpeg settings page should validate the ffprobe binary path is an existing file.");
$this->assertEqual($settings->get('ffmpeg_binary'), $ffmpeg_binary, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg binary path.');
$this->assertEqual($settings->get('ffprobe_binary'), $ffprobe_binary, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffprobe path.');
$this->assertEqual($settings->get('execution_timeout'), $execution_timeout, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg command time path.');
$this->assertEqual($settings->get('threads_amount'), $threads_amount, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg command threads number.');
$this->assertSession()->pageTextContains("File not found: $invalidFilenames[0]");
$this->assertSession()->pageTextContains("File not found: $invalidFilenames[1]");
$this->assertEquals($settings->get('ffmpeg_binary'), $ffmpeg_binary, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg binary path.');
$this->assertEquals($settings->get('ffprobe_binary'), $ffprobe_binary, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffprobe path.');
$this->assertEquals($settings->get('execution_timeout'), $execution_timeout, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg command time path.');
$this->assertEquals($settings->get('threads_amount'), $threads_amount, 'Submitting he PHP-FFMpeg settings page with invalid values should not update the ffmpeg command threads number.');
}
/**
......
......@@ -40,12 +40,12 @@ class PHPFFMpegCacheTest extends UnitTestCase {
*
* @var array
*/
public static $modules = ['php_ffmpeg'];
protected static $modules = ['php_ffmpeg'];
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->backend = (new MemoryBackendFactory())->get('php_ffmpeg');
$this->prefix = $this->randomMachineName();
......@@ -59,8 +59,8 @@ class PHPFFMpegCacheTest extends UnitTestCase {
$cid = $this->randomMachineName();
$value = $this->randomMachineName();
$this->backend->set("{$this->prefix}:{$cid}", $value);
self::assertEquals($this->cache->fetch($cid), $value, 'PHPFFMpeg::get() should return the value stored in the backend when it exists.');
$this->assertFalse($this->cache->fetch($this->randomMachineName()), 'PHPFFMpeg::get() should return FALSE when no value exist in the backend.');
self::assertEquals($value, $this->cache->getItem($cid)->get(),'PHPFFMpeg::get() should return the value stored in the backend when it exists.');
$this->assertFalse($this->cache->getItem($this->randomMachineName())->isHit(), 'PHPFFMpeg::get() should return FALSE when no value exist in the backend.');
}
/**
......@@ -70,8 +70,8 @@ class PHPFFMpegCacheTest extends UnitTestCase {
$cid = $this->randomMachineName();
$value = $this->randomMachineName();
$this->backend->set("{$this->prefix}:{$cid}", $value);
self::assertTrue($this->cache->contains($cid), 'PHPFFMpeg::contains() should return TRUE when a value exists in the backend.');
self::assertFalse($this->cache->contains($this->randomMachineName()), 'PHPFFMpeg::contains() should return FALSE when no value exist in the backend.');
self::assertTrue($this->cache->hasItem($cid), 'PHPFFMpeg::contains() should return TRUE when a value exists in the backend.');
self::assertFalse($this->cache->hasItem($this->randomMachineName()), 'PHPFFMpeg::contains() should return FALSE when no value exist in the backend.');
}
/**
......@@ -80,8 +80,10 @@ class PHPFFMpegCacheTest extends UnitTestCase {
public function testSave() {
$cid = $this->randomMachineName();
$value = $this->randomMachineName();
$this->cache->save($cid, $value);
self::assertEquals($this->backend->get("{$this->prefix}:{$cid}")->data, $value, 'PHPFFMpeg::save() should set the value in the backend.');
$item = $this->cache->getItem($cid);
$item->set($value);
$this->cache->save($item);
self::assertEquals($value, $this->backend->get("{$this->prefix}:{$cid}")->data, 'PHPFFMpeg::save() should set the value in the backend.');
}
/**
......@@ -91,15 +93,8 @@ class PHPFFMpegCacheTest extends UnitTestCase {
$cid = $this->randomMachineName();
$value = $this->randomMachineName();
$this->backend->set("{$this->prefix}:{$cid}", $value);
$this->cache->delete($cid);
$this->cache->deleteItem($cid);
self::assertFalse($this->backend->get("{$this->prefix}:{$cid}"), 'PHPFFMpeg::delete() should clear the value in the backend.');
}
/**
* Test for PHPFFMpeg::getStats().
*/
public function testGetStats() {
self::assertNull($this->cache->getStats(), 'PHPFFMpeg::getStats() should return NULL.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment