Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add multiple uploadables feature#1342

Merged
l3pp4rd merged 6 commits into
doctrine-extensions:masterfrom
tamcy:pull-req-1
Mar 8, 2016
Merged

Add multiple uploadables feature#1342
l3pp4rd merged 6 commits into
doctrine-extensions:masterfrom
tamcy:pull-req-1

Conversation

@tamcy

@tamcy tamcy commented Jun 24, 2015

Copy link
Copy Markdown

Ref: #961

This changeset adds multiple uploadables support in a single entity.

  • A new identifier property is added to all annotations in the uploadable familty (@Uploadable
    @UploadableFileMimeType, @UploadableFileName, @UploadableFilePath, and @UploadableFileSize), with a default value _default. This ensures that no code change is needed in single upload situation.
  • A new @Uploadables annotation added to support multiple uploadable behavior.

The bad thing is I only added multiple support to annotation (I probably don't have spare time to write and test the yml and xml config, so need external help). The good thing is the original configuration won't break.

However there are cases of potential bc-break:

  • A new parameter identifier is also added to FilenameGeneratorInterface::generate() as the forth argument. Currently this is used by the FilenameGeneratorSha1 class to prevent having the same SHA1 result when the same filename and extension are passed to different file fields (with different identifiers) in the same entity. This may affect users who implements their own FilenameGeneratorInterface.
  • Visibility of method processFile() and moveFile() in UploadableListener changed from public to protected because their signature are changed and they don't look right to be public. This may affect users who override the original UploadableListener.

Finally, not related to this project, but still worth mentioning is that a change to stof's DoctrineExtensionsBundle is also needed to support multiple uploadables in a single entity. Modify the markEntityToUpload() method of \Stof\DoctrineExtensionsBundle\Uploadable\UploadableManager as below:

    public function markEntityToUpload($entity, $fileInfo, $identifier = '_default')
    {
        if (is_object($fileInfo) && $fileInfo instanceof UploadedFile) {
            $fileInfoClass = $this->fileInfoClass;

            $fileInfo = new $fileInfoClass($fileInfo);
        }

        $this->listener->addEntityFileInfo($entity, $fileInfo, $identifier);
    }

Usage of this method will become:

$manager->markEntityToUpload($file, $uploadedFile, 'image_thumb');

@l3pp4rd

l3pp4rd commented Jun 27, 2015

Copy link
Copy Markdown
Contributor

thanks it looks like a great improvement, regarding YML and XML hope people will contribute if they need it, I will merge it with minor version change, since it is worth mentioning about the possible BC if extended.

@l3pp4rd l3pp4rd added this to the Arya Stark milestone Jun 27, 2015
@l3pp4rd l3pp4rd modified the milestones: 2.5.0, Arya Stark Oct 2, 2015
l3pp4rd added a commit that referenced this pull request Mar 8, 2016
Add multiple uploadables feature
@l3pp4rd l3pp4rd merged commit 97b67d2 into doctrine-extensions:master Mar 8, 2016
@l3pp4rd

l3pp4rd commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

hey @stof that may have effect on the bundle as mentioned. I think I'll stop any changes to API after 3.0.0, so probably these will be the last changes to adapt unless someone starts to maintain extensions apart from myself :) 3.0.0 won't be released soon, few months at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants