Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
WE.SpreadsheetImport
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Labels
Merge Requests
0
Merge Requests
0
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
packages
WE.SpreadsheetImport
Commits
9fe4b813
Commit
9fe4b813
authored
Oct 28, 2016
by
Chivy Lim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TAKS] Add Model validation on importing service
refs KIME-3603
parent
c1d31909
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
Classes/WE/SpreadsheetImport/Command/SpreadsheetImportCommandController.php
...heetImport/Command/SpreadsheetImportCommandController.php
+1
-1
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
+20
-3
No files found.
Classes/WE/SpreadsheetImport/Command/SpreadsheetImportCommandController.php
View file @
9fe4b813
...
...
@@ -69,7 +69,7 @@ class SpreadsheetImportCommandController extends CommandController {
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_COMPLETED
);
$this
->
spreadsheetImportRepository
->
update
(
$spreadsheetImport
);
$this
->
outputFormatted
(
'Spreadsheet has been
ex
ported. (totalInserted: %d, totalUpdated: %d, totalDeleted: %d, totalSkipped: %d)'
,
$this
->
outputFormatted
(
'Spreadsheet has been
im
ported. (totalInserted: %d, totalUpdated: %d, totalDeleted: %d, totalSkipped: %d)'
,
array
(
$spreadsheetImport
->
getTotalInserted
(),
$spreadsheetImport
->
getTotalUpdated
(),
$spreadsheetImport
->
getTotalDeleted
(),
$spreadsheetImport
->
getTotalSkipped
()));
}
else
{
$this
->
outputFormatted
(
'There is no spreadsheet importing in queue.'
);
...
...
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
9fe4b813
...
...
@@ -70,6 +70,12 @@ class SpreadsheetImportService {
*/
protected
$propertyMapper
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Validation\ValidatorResolver
*/
protected
$validatorResolver
;
/**
* @param \WE\SpreadsheetImport\Domain\Model\SpreadsheetImport $spreadsheetImport
*
...
...
@@ -187,6 +193,7 @@ class SpreadsheetImportService {
$objectIds
=
array
();
$domain
=
$this
->
domain
;
$objectRepository
=
$this
->
getDomainRepository
();
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$domain
);
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$file
=
$this
->
spreadsheetImport
->
getFile
()
->
createTemporaryLocalCopy
();
$reader
=
\PHPExcel_IOFactory
::
load
(
$file
);
...
...
@@ -199,21 +206,33 @@ class SpreadsheetImportService {
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
if
(
$this
->
spreadsheetImport
->
isUpdating
())
{
$this
->
setObjectPropertiesByRow
(
$object
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$object
);
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
}
$objectRepository
->
update
(
$object
);
$totalUpdated
++
;
$i
++
;
}
else
{
$totalSkipped
++
;
continue
;
}
}
elseif
(
$this
->
spreadsheetImport
->
isInserting
())
{
$newObject
=
new
$domain
;
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$newObject
);
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
}
$objectRepository
->
add
(
$newObject
);
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$totalInserted
++
;
$i
++
;
}
else
{
$totalSkipped
++
;
continue
;
}
if
(
$i
>=
$numberOfRecordsToPersist
)
{
$this
->
persistenceManager
->
persistAll
();
...
...
@@ -224,7 +243,6 @@ class SpreadsheetImportService {
// remove objects which are not exist on the spreadsheet
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$objectIds
);
$i
=
0
;
foreach
(
$notExistingObjects
as
$object
)
{
$objectRepository
->
remove
(
$object
);
$totalDeleted
++
;
...
...
@@ -246,8 +264,7 @@ class SpreadsheetImportService {
* @return \TYPO3\Flow\Persistence\RepositoryInterface
*/
private
function
getDomainRepository
()
{
$domainClassName
=
$this
->
domain
;
$repositoryClassName
=
preg_replace
(
array
(
'/\\\Model\\\/'
,
'/$/'
),
array
(
'\\Repository\\'
,
'Repository'
),
$domainClassName
);
$repositoryClassName
=
preg_replace
(
array
(
'/\\\Model\\\/'
,
'/$/'
),
array
(
'\\Repository\\'
,
'Repository'
),
$this
->
domain
);
/** @var RepositoryInterface $repository */
$repository
=
$this
->
objectManager
->
get
(
$repositoryClassName
);
return
$repository
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment