Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_news
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_news
Commits
0cba5ced
Commit
0cba5ced
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Fixing file reference issues
parent
e35644c1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Command/MigrateNewsCommandController.php
+39
-32
39 additions, 32 deletions
Classes/Command/MigrateNewsCommandController.php
with
39 additions
and
32 deletions
Classes/Command/MigrateNewsCommandController.php
+
39
−
32
View file @
0cba5ced
...
...
@@ -31,6 +31,8 @@ use SGalinski\SgNews\Domain\Model\Tag;
use
TYPO3\CMS\Backend\FrontendBackendUserAuthentication
;
use
TYPO3\CMS\Core\Database\DatabaseConnection
;
use
TYPO3\CMS\Core\DataHandling\DataHandler
;
use
TYPO3\CMS\Core\Resource\File
;
use
TYPO3\CMS\Core\Resource\FileInterface
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Domain\Model\FileReference
;
use
TYPO3\CMS\Extbase\Mvc\Controller\CommandController
;
...
...
@@ -178,21 +180,22 @@ class MigrateNewsCommandController extends CommandController {
$newsPage
->
addTag
(
$matchingTag
);
}
/** @var FileReference $image */
$image
=
$this
->
getMatchingImage
(
$row
);
if
(
$image
!==
NULL
)
{
$newsPage
->
addTeaser1Image
(
$image
);
$originalResource
=
$image
->
getOriginalResource
();
if
(
$originalResource
!==
NULL
)
{
$originalFile
=
$originalResource
->
getOriginalFile
();
if
(
$originalFile
!==
NULL
)
{
$teaserImage2
=
$this
->
fileReferenceRepository
->
addFileReferenceFromFile
(
$originalFile
,
$this
->
newsPagesMap
[
$row
[
'uid'
]],
$this
->
newsPagesMap
[
$row
[
'uid'
]],
'pages'
,
'tx_sgnews_teaser2_image'
);
$newsPage
->
addTeaser2Image
(
$teaserImage2
);
}
/** @var File $image */
$file
=
$this
->
getMatchingFile
(
$row
);
if
(
$file
instanceof
File
)
{
$teaserImage1
=
$this
->
fileReferenceRepository
->
addFileReferenceFromFile
(
$file
,
$this
->
newsPagesMap
[
$row
[
'uid'
]],
$this
->
newsPagesMap
[
$row
[
'uid'
]],
'pages'
,
'tx_sgnews_teaser1_image'
);
if
(
$teaserImage1
)
{
$newsPage
->
addTeaser1Image
(
$teaserImage1
);
$teaserImage2
=
$this
->
fileReferenceRepository
->
addFileReferenceFromFile
(
$file
,
$this
->
newsPagesMap
[
$row
[
'uid'
]],
$this
->
newsPagesMap
[
$row
[
'uid'
]],
'pages'
,
'tx_sgnews_teaser2_image'
);
$newsPage
->
addTeaser2Image
(
$teaserImage2
);
}
}
...
...
@@ -213,33 +216,37 @@ class MigrateNewsCommandController extends CommandController {
* Get the image file matching the news
*
* @param array $row
* @return null|FileReference
* @return null|FileInterface
* @throws \Exception
*/
private
function
getMatchingImage
(
array
$row
)
{
private
function
getMatchingFile
(
array
$row
)
{
// match old page id with old file reference id
/** @var DatabaseConnection $db */
$db
=
$GLOBALS
[
'TYPO3_DB'
];
$where
=
'tablenames = "tx_news_domain_model_news" AND fieldname = "fal_media" AND uid_foreign = '
.
$row
[
'uid'
];
$where
=
'tablenames = "tx_news_domain_model_news" AND fieldname = "fal_media" AND uid_foreign = '
.
$this
->
newsPagesMap
[
$row
[
'uid'
]];
/** @var \mysqli_result $result */
$result
=
$db
->
exec_SELECTgetSingleRow
(
'uid, uid_local'
,
'sys_file_reference'
,
$where
);
if
(
!
$result
)
{
$fileReferenceResult
=
$db
->
exec_SELECTgetSingleRow
(
'uid, uid_local'
,
'sys_file_reference_news_migration'
,
$where
);
if
(
!
$fileReferenceResult
)
{
return
NULL
;
}
$where
=
'uid = '
.
$
r
esult
[
'uid'
];
$db
->
exec_UPDATEquery
(
'sys_file_reference'
,
$where
,
[
'pid'
=>
$this
->
newsPagesMap
[
$row
[
'uid'
]],
'uid_foreign'
=>
$this
->
newsPagesMap
[
$row
[
'uid'
]],
'tablenames'
=>
'pages'
,
'fieldname'
=>
'tx_sgnews_teaser1_image'
]
);
$where
=
'uid = '
.
$
fileReferenceR
esult
[
'uid
_local
'
];
/** @var \mysqli_result $result */
$fileResult
=
$db
->
exec_SELECTgetSingleRow
(
'identifier'
,
'sys_file_news_migration'
,
$where
);
if
(
!
$fileResult
)
{
return
NULL
;
}
$result
=
$this
->
fileReferenceRepository
->
findByUid
((
int
)
$result
[
'uid'
]);
if
(
$result
instanceof
FileReference
)
{
$result
->
setPid
(
$this
->
newsPagesMap
[
$row
[
'uid'
]]);
return
$result
;
$oldIdentifier
=
$fileResult
[
'identifier'
];
$resourceFactory
=
\TYPO3\CMS\Core\Resource\ResourceFactory
::
getInstance
();
$storage
=
$resourceFactory
->
getStorageObject
(
1
);
if
(
!
$storage
->
hasFile
(
$oldIdentifier
))
{
return
NULL
;
}
return
NULL
;
return
$storage
->
getFile
(
$oldIdentifier
)
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment