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 {
...
@@ -69,7 +69,7 @@ class SpreadsheetImportCommandController extends CommandController {
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_COMPLETED
);
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_COMPLETED
);
$this
->
spreadsheetImportRepository
->
update
(
$spreadsheetImport
);
$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
()));
array
(
$spreadsheetImport
->
getTotalInserted
(),
$spreadsheetImport
->
getTotalUpdated
(),
$spreadsheetImport
->
getTotalDeleted
(),
$spreadsheetImport
->
getTotalSkipped
()));
}
else
{
}
else
{
$this
->
outputFormatted
(
'There is no spreadsheet importing in queue.'
);
$this
->
outputFormatted
(
'There is no spreadsheet importing in queue.'
);
...
...
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
9fe4b813
...
@@ -70,6 +70,12 @@ class SpreadsheetImportService {
...
@@ -70,6 +70,12 @@ class SpreadsheetImportService {
*/
*/
protected
$propertyMapper
;
protected
$propertyMapper
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Validation\ValidatorResolver
*/
protected
$validatorResolver
;
/**
/**
* @param \WE\SpreadsheetImport\Domain\Model\SpreadsheetImport $spreadsheetImport
* @param \WE\SpreadsheetImport\Domain\Model\SpreadsheetImport $spreadsheetImport
*
*
...
@@ -187,6 +193,7 @@ class SpreadsheetImportService {
...
@@ -187,6 +193,7 @@ class SpreadsheetImportService {
$objectIds
=
array
();
$objectIds
=
array
();
$domain
=
$this
->
domain
;
$domain
=
$this
->
domain
;
$objectRepository
=
$this
->
getDomainRepository
();
$objectRepository
=
$this
->
getDomainRepository
();
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$domain
);
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$file
=
$this
->
spreadsheetImport
->
getFile
()
->
createTemporaryLocalCopy
();
$file
=
$this
->
spreadsheetImport
->
getFile
()
->
createTemporaryLocalCopy
();
$reader
=
\PHPExcel_IOFactory
::
load
(
$file
);
$reader
=
\PHPExcel_IOFactory
::
load
(
$file
);
...
@@ -199,21 +206,33 @@ class SpreadsheetImportService {
...
@@ -199,21 +206,33 @@ class SpreadsheetImportService {
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
if
(
$this
->
spreadsheetImport
->
isUpdating
())
{
if
(
$this
->
spreadsheetImport
->
isUpdating
())
{
$this
->
setObjectPropertiesByRow
(
$object
,
$row
);
$this
->
setObjectPropertiesByRow
(
$object
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$object
);
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
}
$objectRepository
->
update
(
$object
);
$objectRepository
->
update
(
$object
);
$totalUpdated
++
;
$totalUpdated
++
;
$i
++
;
$i
++
;
}
else
{
}
else
{
$totalSkipped
++
;
$totalSkipped
++
;
continue
;
}
}
}
elseif
(
$this
->
spreadsheetImport
->
isInserting
())
{
}
elseif
(
$this
->
spreadsheetImport
->
isInserting
())
{
$newObject
=
new
$domain
;
$newObject
=
new
$domain
;
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$newObject
);
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
}
$objectRepository
->
add
(
$newObject
);
$objectRepository
->
add
(
$newObject
);
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$objectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$totalInserted
++
;
$totalInserted
++
;
$i
++
;
$i
++
;
}
else
{
}
else
{
$totalSkipped
++
;
$totalSkipped
++
;
continue
;
}
}
if
(
$i
>=
$numberOfRecordsToPersist
)
{
if
(
$i
>=
$numberOfRecordsToPersist
)
{
$this
->
persistenceManager
->
persistAll
();
$this
->
persistenceManager
->
persistAll
();
...
@@ -224,7 +243,6 @@ class SpreadsheetImportService {
...
@@ -224,7 +243,6 @@ class SpreadsheetImportService {
// remove objects which are not exist on the spreadsheet
// remove objects which are not exist on the spreadsheet
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$objectIds
);
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$objectIds
);
$i
=
0
;
foreach
(
$notExistingObjects
as
$object
)
{
foreach
(
$notExistingObjects
as
$object
)
{
$objectRepository
->
remove
(
$object
);
$objectRepository
->
remove
(
$object
);
$totalDeleted
++
;
$totalDeleted
++
;
...
@@ -246,8 +264,7 @@ class SpreadsheetImportService {
...
@@ -246,8 +264,7 @@ class SpreadsheetImportService {
* @return \TYPO3\Flow\Persistence\RepositoryInterface
* @return \TYPO3\Flow\Persistence\RepositoryInterface
*/
*/
private
function
getDomainRepository
()
{
private
function
getDomainRepository
()
{
$domainClassName
=
$this
->
domain
;
$repositoryClassName
=
preg_replace
(
array
(
'/\\\Model\\\/'
,
'/$/'
),
array
(
'\\Repository\\'
,
'Repository'
),
$this
->
domain
);
$repositoryClassName
=
preg_replace
(
array
(
'/\\\Model\\\/'
,
'/$/'
),
array
(
'\\Repository\\'
,
'Repository'
),
$domainClassName
);
/** @var RepositoryInterface $repository */
/** @var RepositoryInterface $repository */
$repository
=
$this
->
objectManager
->
get
(
$repositoryClassName
);
$repository
=
$this
->
objectManager
->
get
(
$repositoryClassName
);
return
$repository
;
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