Problem/Motivation

Make the module available for Drupal 8

Proposed resolution

  1. Some functions in the module file have be converted to services
  2. Drupal 8's logger can be used to replace the custom logger solution of the module, the corresponding tests can be dropped
  3. Cache can be implemented by adding an adapter class that implements the Doctrine cache interface but uses a Drupal cache internally

Comments

s_leu created an issue. See original summary.

s_leu’s picture

Status: Active » Needs review
StatusFileSize
new38.01 KB

Here's a first patch.

berdir’s picture

Status: Needs review » Needs work

Good start.

  1. +++ b/config/install/php_ffmpeg.settings.yml
    @@ -0,0 +1,5 @@
    +php_ffmpeg_ffmpeg_binary: ''
    +php_ffmpeg_ffprobe_binary: ''
    +php_ffmpeg_timeout: 0
    +php_ffmpeg_threads: 0
    +php_ffmpeg_monolog_channel: null
    

    no need to repeat the module prefix in the config keys, they are already namespaced.

  2. +++ b/php_ffmpeg.info.yml
    @@ -0,0 +1,9 @@
    +test_dependencies:
    +  - ctools
    +  - token
    

    really needed or copied from somewhere?

  3. +++ b/php_ffmpeg.module
    @@ -1,118 +1,5 @@
     /**
      * @file
    - * Hook implementations and shared functions for the PHP-FFMpeg module.
    + * Hook implementations functions for the PHP-FFMpeg module.
      */
    

    you can remove the file if there is nothing left in here. although technically, all modules should have a hook_help() implementation, so keeping it is fine too.

  4. +++ b/src/FFMpegCache.php
    @@ -0,0 +1,72 @@
    +
    +/**
    + * @file
    + * @todo add file description
    + */
    

    no @file on classes anymore.

  5. +++ b/src/FFMpegCache.php
    @@ -0,0 +1,72 @@
    +/**
    + * Class FFMpegCache
    + *
    + * Adapter between Doctrine cache needed by FFMPeg library and Drupal cache.
    + */
    +class FFMpegCache implements Cache {
    

    No need for that standard Class XY thing that phpstorm ads. just keep the second line.

  6. +++ b/src/FFMpegCache.php
    @@ -0,0 +1,72 @@
    +   */
    +  public function fetch($id) {
    +    return $this->cache->get($id);
    +  }
    +
    

    wondering if we should have a prefix, no idea what those cache ids will look like.

  7. +++ b/src/FFMpegFactory.php
    @@ -0,0 +1,63 @@
    + * @file
    + * Contains service for the FFMPeg API integration.
    + */
    +
    

    also remove

  8. +++ b/src/FFMpegFactory.php
    @@ -0,0 +1,63 @@
    +        \Drupal::logger('php_ffmpeg'),
    +        \Drupal::service('php_ffmpeg.cache')
    

    you can inject those into the factory. to do that with the logger, you can define it as a service too, core has examples.

  9. +++ b/src/FFMpegFactory.php
    @@ -0,0 +1,63 @@
    +      'ffmpeg.binaries'  => \Drupal::config('php_ffmpeg.settings')->get('php_ffmpeg_ffmpeg_binary'),
    +      'ffprobe.binaries' => \Drupal::config('php_ffmpeg.settings')->get('php_ffmpeg_ffprobe_binary'),
    +      'timeout'          => \Drupal::config('php_ffmpeg.settings')->get('php_ffmpeg_timeout'),
    

    same for the config, inject the config factory.

  10. +++ b/src/Form/PhpFFMpegSettings.php
    @@ -0,0 +1,109 @@
    +    $form['php_ffmpeg_ffmpeg_binary'] = [
    +      '#type' => 'textfield',
    +      '#title' => t('ffmpeg binary'),
    +      '#description' => t('Path to the ffmpeg binary. Leave empty if the binary is located within system PATH.'),
    

    I would remove the prefix here as well.

  11. +++ b/src/Form/PhpFFMpegSettings.php
    @@ -0,0 +1,109 @@
    +    if ($form_state->getValue(['php_ffmpeg_timeout']) && (!is_numeric($form_state->getValue(['php_ffmpeg_timeout'])) || $form_state->getValue(['php_ffmpeg_timeout']) < 0 || (intval($form_state->getValue(['php_ffmpeg_timeout'])) != $form_state->getValue(['php_ffmpeg_timeout'])))) {
    +      $form_state->setErrorByName('php_ffmpeg_timeout', t('The value of the Timeout field must be a positive integer.'));
    +    }
    +    if ($form_state->getValue(['php_ffmpeg_threads']) && (!is_numeric($form_state->getValue(['php_ffmpeg_threads'])) || $form_state->getValue(['php_ffmpeg_threads']) < 0) || (intval($form_state->getValue(['php_ffmpeg_threads'])) != $form_state->getValue(['php_ffmpeg_threads']))) {
    +      $form_state->setErrorByName('php_ffmpeg_threads', t('The value of the Threads field must be zero or a positive integer.'));
    +    }
    

    you can do this using #type number and set #step to 1 and #max/#min accordingly.

  12. +++ b/src/Tests/PHPFFMpegTestCase.php
    @@ -0,0 +1,111 @@
    +
    +  protected $profile = 'standard';
    +
    

    standard is going to be extremely slow. lets try to change to testing.

  13. +++ /dev/null
    @@ -1,128 +0,0 @@
    -    parent::setUp();
    -    $this->backend = new PHPFFMpegCacheTestCaseMemoryCache();
    -    $this->prefix = $this->randomString();
    -    $this->cache = new PHPFFMpegCache($this->backend, $this->prefix);
    -  }
    -
    -  public function testFetch() {
    -    $cid = $this->randomString();
    -    $value = $this->randomString();
    -    $this->backend->set("{$this->prefix}:{$cid}", $value);
    

    we still have the adapter, so lets keep this test.

    Should be quite easy to convert this to a unit test that uses mocks.

s_leu’s picture

Status: Needs work » Needs review
StatusFileSize
new48.15 KB
new40.49 KB
berdir’s picture

  1. +++ b/src/Tests/PHPFFMpegTestCase.php
    index 0000000..2e8d807
    --- /dev/null
    
    --- /dev/null
    +++ b/tests/src/Kernel/PHPFFMpegCacheTest.test
    

    wrong file extension.

  2. +++ b/tests/src/Kernel/PHPFFMpegCacheTest.test
    @@ -0,0 +1,64 @@
    +class PHPFFMpegCacheTest extends KernelTestBase {
    

    a kernel tests works too I suppose, although a unit test here would be nicer IMHO

berdir’s picture

Working on this in a PR now, to have tests run: https://github.com/FloeDesignTechnologies/drupal-php-ffmpeg/pull/1

pbuyle’s picture

Awesome!

I've not worked with Drupal 8 much but this looks good to me. Anything missing or do you consider this RTBC?

Also, would you be interested becoming maintainer for the Drupal 8 version?

pbuyle’s picture

Currently the port does not seem to support Monolog but retains configuration for a Monolog channel. I'm not convinced Monolog support is a must-have in Drupal8, so removing it from the settings should be enough.

berdir’s picture

The logger adapter is removed because Drupal watchdog already implements the psr logger interface.

We inject a watchdog channel logger, someone could alter the service definition and log it to another place, but I think it is more likely for a drupal site to switch out the dblog module completely and log everything somewhere else?

I think it's pretty much ready, still need to do some final tests, however. I just pushed a small commit with a problem that I noticed that broke the simpletest UI, that is also fixed now. Tests in the PR are passing, so that's good. I can clean up those commits a bit if you want. Committing as a single patch/commit is also fine with me.

Sure, I can help with maintaining, can't promise much since I have a ton of modules where I'm involved. But I'll try to follow eventual 8.x issues and help with reviews/commits.

pbuyle’s picture

I've seen injection of the logger. Thanks to the service injection and the service override in Drupal, it can easily be replaced if wanted. So Monolog support in the module would not be relevant. We just need to remove the code for the monolog_channel setting (in the settings form and settings definition yaml files).

This is a very low maintenance module (the module is simple, and there isn't many users anyway). I'll add you as maintainer. I can still take care of the merge if you want.

pbuyle’s picture

Le'ts not forget to update the README (and module description on drupal.org) too.

berdir’s picture

Ok, updated the README, removed the monolog setting and added the missing probe service.

I think we're good to go?

Do you want me to merge this to d.o? What is your process with the github repository, is drupal.org the main repository and the other is then updated? (I can't push to that I guess)

pbuyle’s picture

Yes, we are good to go.

I would like to keep the repository on d.o the main one. The GitHub one should be a mirror. But I'm fine as long as both repo are kept fully in sync. I added you as collaborator on GitHub, so you can now commit there too. Which mean I'm okay with you handling the merging. If not done, I'll handle it myself in the coming day.

Once this is done, I'll make a 8.x-1.0 release of the module.

  • Berdir committed 68904c0 on 8.x-1.x authored by s_leu
    Issue #2777531 by s_leu, Berdir: Initial Drupal 8 port
    
  • Berdir committed 1ea0416 on 8.x-1.x
    Issue #2777531 by Berdir: Updating travis.yml
    
  • Berdir committed 1a9320b on 8.x-1.x
    Issue #2777531 by Berdir: Remove monolog setting
    
  • Berdir committed 0bdb3cd on 8.x-1.x
    Issue #2777531 by Berdir: Added missing probe service, update and...
berdir’s picture

Assigned: Unassigned » pbuyle
Status: Needs review » Reviewed & tested by the community

Ok, I pushed the code to drupal.org and github, looks like I can't create releases, so assigning to you for that.

Would be great if you could do that asap, then I can already switch to an official release (I don't care about dev or alpha or stable, as long as there's anything) in our project, which will make updating easier.

pbuyle’s picture

I made a RC release (and a dev one too). If nothing comes up before, I'll make it the 8.x-1.0 release around September 1st.

pbuyle’s picture

@berdir Do you want MD Systems to be added as supporting organization for the development of the D8 version ?

berdir’s picture

Yes please :)

berdir’s picture

Status: Reviewed & tested by the community » Fixed

I'd say we can close this issue now?

pbuyle’s picture

Yes off course.
Thank you for the port.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

pbuyle’s picture

Version 8.x-1.0 released. Again, thanks Berdir, s_leu and MD System for the port to Drupal 8.