Devise\Pages\Fields\Handlers\AudioFieldUpdated::handle PHP Method

handle() public method

This is called anytime after we update a video field in devise
public handle ( Field $field, array $input ) : array
$field Field
$input array
return array
    public function handle($field, $input)
    {
        //
        // can't process imaginary files (unless you're awesome)
        //
        if ($this->noAudioPathDefined($field, $input)) {
            return;
        }
        //
        // get the current settings we should use
        //
        $settings = $this->buildSettings($field, $input);
        //
        // need some way to determine if settings have changed since
        // the last time we ran this b/c I don't want this to run
        // every single time we save something on the video field,
        // only when something has been changed we create a job
        //
        list($unprocessed, $duplicatedFormats) = $this->findUnprocessedFiles($field, $settings);
        //
        // update this fields's {format}_url
        //
        $this->updateVersionUrls($field, $unprocessed, $duplicatedFormats);
        //
        // only process videos that haven't been processed yet
        //
        if ($unprocessed) {
            $this->Encoder->create($this->MediaPaths->zencoderUrl($field->values->original), $unprocessed);
            $this->createTempHoldingFiles($unprocessed);
        }
    }

Usage Example

Example #1
0
 public function test_it_handles_updates()
 {
     $FieldValue = new FieldValue('{}');
     $MediaPathHelper = m::mock('Devise\\Media\\MediaPaths');
     $DvsField = m::mock('DvsField');
     $DvsField->shouldReceive('getAttribute')->with('values')->andReturn($FieldValue);
     $DvsField->shouldReceive('setAttribute')->with('json_value', $FieldValue->toJSON());
     $DvsField->shouldReceive('save')->times(1);
     $Encoder = m::mock('Devise\\Media\\Encoding\\ZencoderJob');
     $Framework = new \Devise\Support\Framework();
     $AudioFieldUpdated = new AudioFieldUpdated($MediaPathHelper, $Encoder, $Framework);
     $AudioFieldUpdated->handle($DvsField, []);
 }