Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple uploadables feature #1342

Merged
merged 6 commits into from Mar 8, 2016
Merged

Add multiple uploadables feature #1342

merged 6 commits into from Mar 8, 2016

Conversation

tamcy
Copy link

@tamcy tamcy commented Jun 24, 2015

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
Copy link
Contributor

l3pp4rd commented Jun 27, 2015

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
Copy link
Contributor

l3pp4rd commented Mar 8, 2016

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.

None yet

2 participants