robbiepaul / cloudconvert-laravel

A Laravel wrapper for the CloudConvert API
177 stars 34 forks source link

Singleton prevents multiple conversions. #16

Closed IanCaunce closed 8 years ago

IanCaunce commented 8 years ago

I have noticed that inside your service provider you run

$this->app['cloudconvert'] = $this->app->share(function($app)
{
    return new CloudConvert(config('cloudconvert'));
});

which means that each time I call a method via the facade the same instance of RobbieP\CloudConvertLaravel\CloudConvert is given back.

On line 308 of CloudConvert.php you check to see if the resource is empty before setting it and if not you don't set the resource again. This means that you can only ever upload and convert one file. If you attempt to upload multiple files, the first file will be re-uploaded and converted multiple times.

robbiepaul commented 8 years ago

Thanks again Ian,

I've added a reset function to clear those vars.

See commit ba0b59a8eafdbb8bb6b767b6986b8df1d29d382b

I've ran a couple of quick tests and it's working as expected. Let me know if you notice anything different.

Robbie

IanCaunce commented 8 years ago

Hi,

Thanks for the patch but unfortunately it doesn't fix the issue when your using non blocking logic. Calling convert on the CloudConvert instance doesn't call the reset method. Manually calling reset also doesn't work because the process isn't finished.

robbiepaul commented 8 years ago

I've added a method to create a new instance. For example

$cloudconvert1 = CloudConvert::file('/a/path/to/file.mov')
                             ->callback('http://myserver.com/save_file.php')
                             ->convert('mp4');

$cloudconvert2 = CloudConvert::newInstance();
$cloudconvert2->file('/a/path/to/file2.mov')
                             ->callback('http://myserver.com/save_file.php')
                             ->convert('mp4');

Hope that works for your use case.

See a9a14d70fa21f1b9008d41b95c550bbf2179d24e

IanCaunce commented 8 years ago

Everything seems to be working fine now. Thanks again for fixing it.