简体   繁体   English

TYPO3文件引用添加两个文件

[英]TYPO3 filereference adding two files

I have TYPO3 7.6.18 我有TYPO3 7.6.18

this is my code: 这是我的代码:

    $newVideo = new \Istar\Fefiles\Domain\Model\Video();
    $videoName = $video['name'];
    $videoTmpName = $video['tmp_name'];
    $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
    $storage = $resourceFactory->getDefaultStorage();
    $folder = $storage->getFolder("user_upload/");
    $movedFile = $storage->addFile($videoTmpName, $folder, $videoName);
    $newFileReference = $this->objectManager$this->objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference');
    $newFileReference->setFile($movedFile);
    $newVideo->setVideo($newFileReference);
        $this->videoRepository->add($newVideo);
        $persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
        $persistenceManager->persistAll();

The problem is it added two files to field video file reference. 问题是它向现场视频文件参考添加了两个文件。 It's very sudenly! 非常突然! And second file is't the same, it's diferent files. 第二个文件是不同的,它是不同的文件。 I sure, I send one file. 我确定,我发送了一个文件。 Where may be the problem ? 问题可能出在哪里?

I have model photo, and there is field image 我有模特照片,并且有野外图片

'image' => [
    'exclude' => 0,
    'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:image',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
        'appearance' => [
            'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
        ],
        'maxitems' => 1,
    ], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],

Anf I see that when I create photo from BE, and upload image - this add second image, which was uploaded on site early. Anf我从BE创建照片并上传图片时看到-添加第二张图片,该图片早已在网站上上传。 This is very strange! 这很奇怪! What happens ? 怎么了 ?

My video model: 我的影片模型:

<?php
namespace Istar\Fefiles\Domain\Model;

class Video extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
    /**
     * @var bool
     */
    public $allow_for_user = true;

    /**
     * Title
     *
     * @var string
     * @validate NotEmpty
     */
    protected $title = '';

    /**
     * Description
     *
     * @var string
     */
    protected $description = '';

    /**
     * rulesDescription
     *
     * @var string
     */
    protected $rulesDescription = '';

    /**
     * User
     *
     * @var \Fhk\Feusersplus\Domain\Model\User>
     */
    protected $user;

    /**
     * Videocategory
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory>
     */
    protected $videocategory;

    /**
     * Videocomment
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment>
     * @cascade remove
     */
    protected $comment;

    /**
     * Allow
     *
     * @var int
     */
    protected $allow = 0;

     /**
     * fskcheck
     *
     * @var int
     */
    protected $fskcheck = 0;

     /**
     * private
     *
     * @var int
     */
    protected $private = 0;

    /**
     * Video
     * @validate NotEmpty
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     * @cascade remove
     */
    protected $video;

    /**
     * preview
     *
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     * @cascade remove
     */
    protected $preview = null;

    /**
     * blurred
     *
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     * @cascade remove
     */
    protected $blurred = null;

    /**
     * Crdate
     *
     * @var int
     * @validate NotEmpty
     */
    protected $crdate = 0;

    /**
     * Returns the title
     *
     * @return string $title
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Sets the title
     *
     * @param string $title
     * @return void
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * Returns the description
     *
     * @return string $description
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Sets the description
     *
     * @param string $description
     * @return void
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Returns the rulesDescription
     *
     * @return string $rulesDescription
     */
    public function getRulesDescription()
    {
        return $this->rulesDescription;
    }

    /**
     * Sets the rulesDescription
     *
     * @param string $rulesDescription
     * @return void
     */
    public function setRulesDescription($rulesDescription)
    {
        $this->rulesDescription = $rulesDescription;
    }

    /**
     * Returns the video
     *
     * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
     */
    public function getVideo()
    {
        return $this->video;
    }

    /**
     * Returns the videocategory
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory> $videocategory
     */
    public function getVideocategory()
    {
        return $this->videocategory;
    }

    /**
     * Sets the videocategory
     *
     * @return void
     */
    public function setVideocategory($videocategory)
    {
        $this->videocategory = $videocategory;
    }

    /**
     * Returns the comment
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment> $comment
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * Sets the comment
     *
     * @return void
     */
    public function setComment($comment)
    {
        $this->comment = $comment;
    }

    /**
     * Adds a comments to the video
     *
     * @param \Istar\Fefiles\Domain\Model\Videocomment $comment
     * @return void
     * @api
     */
    public function addComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
    {
        $this->comment->attach($comment);
    }

    /**
     * Removes a comment from the video
     *
     * @param \Istar\Fefiles\Domain\Model\Videocomment $comment
     * @return void
     * @api
     */
    public function removeComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
    {
        $this->comment->detach($comment);
    }


    /**
     * Returns the user
     *
     * @return \Fhk\Feusersplus\Domain\Model\User> $user
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Sets the user
     *
     * @return void
     */
    public function setUser($user)
    {
        $this->user = $user;
    }

    /**
     * Returns the allow
     *
     * @return int
     */
    public function getAllow()
    {
        return $this->allow;
    }

    /**
     * Sets the video
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
     * @return void
     */
    public function setVideo($video)
    {
        $this->video = $video;
    }

    /**
     * Returns the preview
     *
     * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
     */
    public function getPreview()
    {
        return $this->preview;
    }

    /**
     * Sets the preview
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
     *
     * @return void
     */
    public function setPreview($preview)
    {
        $this->preview = $preview;
    }

    /**
     * Returns the blurred
     *
     * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
     */
    public function getBlurred()
    {
        return $this->blurred;
    }

    /**
     * Sets the blurred
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
     *
     * @return void
     */
    public function setBlurred($blurred)
    {
        $this->blurred = $blurred;
    }

    /**
     * Returns the fskcheck
     *
     * @return int
     */
    public function getFskcheck()
    {
        return $this->fskcheck;
    }

    /**
     * Sets the fskcheck
     *
     * @return void
     */
    public function setFskcheck($fskcheck)
    {
        $this->fskcheck = $fskcheck;
    }
    /**
     * Returns the Private
     *
     * @return int
     */
    public function getPrivate()
    {
        return $this->private;
    }

    /**
     * Sets the private
     *
     * @return void
     */
    public function setPrivate($private)
    {
        $this->private = $private;
    }

    /**
     * Returns the crdate
     * @return int $crdate
     */
    public function getCrdate()
    {
        return $this->crdate;
    }

    /**
     * Sets the crdate
     *
     * @param int $crdate
     * @return void
     */
    public function setCrdate($crdate)
    {
        $this->crdate = $crdate;
    }

}

Have a look at the sys_file_reference table before and after you create a new record in the backend. 在后端中创建新记录之前和之后,请查看sys_file_reference表。 Is there a new record added? 是否添加了新记录? And after saving an existing record you don't get the random image/video added? 在保存现有记录后,您没有添加随机图像/视频吗?

Solution: 解:

'foreign_match_fields' => array(
                    'fieldname' => 'image',
                    'tablenames' => 'tx_fefiles_domain_model_photo',
                    'table_local' => 'sys_file_reference',
                ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM