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
9af7082e
Commit
9af7082e
authored
Nov 02, 2016
by
Simon Gadient
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RFT] Label changes and code style
refs KIME-4583
parent
36f56676
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
43 deletions
+31
-43
Classes/WE/SpreadsheetImport/Command/SpreadsheetImportCommandController.php
...heetImport/Command/SpreadsheetImportCommandController.php
+8
-8
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
+15
-27
Configuration/Settings.yaml
Configuration/Settings.yaml
+2
-2
Configuration/Settings.yaml.example
Configuration/Settings.yaml.example
+2
-2
Resources/Private/Translations/de/Main.xlf
Resources/Private/Translations/de/Main.xlf
+2
-2
Resources/Private/Translations/en/Main.xlf
Resources/Private/Translations/en/Main.xlf
+2
-2
No files found.
Classes/WE/SpreadsheetImport/Command/SpreadsheetImportCommandController.php
View file @
9af7082e
...
@@ -46,12 +46,12 @@ class SpreadsheetImportCommandController extends CommandController {
...
@@ -46,12 +46,12 @@ class SpreadsheetImportCommandController extends CommandController {
protected
$settings
;
protected
$settings
;
/**
/**
* Import
one pending queued spreadsheet into Domain data, and it will import the next one if it is done
* Import
next queued spreadsheets into domain objects asynchronously.
*/
*/
public
function
importCommand
()
{
public
function
importCommand
()
{
$currentImportingCount
=
$this
->
spreadsheetImportRepository
->
countByImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_IN_PROGRESS
);
$currentImportingCount
=
$this
->
spreadsheetImportRepository
->
countByImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_IN_PROGRESS
);
if
(
$currentImportingCount
>
0
)
{
if
(
$currentImportingCount
>
0
)
{
$this
->
outputFormatted
(
'
There is a progressing importing spreadsheet
.'
);
$this
->
outputFormatted
(
'
Previous spreadsheet import is still in progress
.'
);
$this
->
quit
();
$this
->
quit
();
}
}
/** @var SpreadsheetImport $spreadsheetImport */
/** @var SpreadsheetImport $spreadsheetImport */
...
@@ -67,25 +67,25 @@ class SpreadsheetImportCommandController extends CommandController {
...
@@ -67,25 +67,25 @@ class SpreadsheetImportCommandController extends CommandController {
try
{
try
{
$this
->
spreadsheetImportService
->
import
();
$this
->
spreadsheetImportService
->
import
();
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_COMPLETED
);
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_COMPLETED
);
$this
->
outputFormatted
(
'Spreadsheet has been imported.
(totalInserted: %d, totalUpdated: %d, totalDeleted: %d, totalSkipped: %d)
'
,
$this
->
outputFormatted
(
'Spreadsheet has been imported.
%d inserted, %d updated, %d deleted, %d skipped
'
,
array
(
$spreadsheetImport
->
getTotalInserted
(),
$spreadsheetImport
->
getTotalUpdated
(),
$spreadsheetImport
->
getTotalDeleted
(),
$spreadsheetImport
->
getTotalSkipped
()));
array
(
$spreadsheetImport
->
getTotalInserted
(),
$spreadsheetImport
->
getTotalUpdated
(),
$spreadsheetImport
->
getTotalDeleted
(),
$spreadsheetImport
->
getTotalSkipped
()));
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_FAILED
);
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_FAILED
);
$this
->
outputFormatted
(
'Spreadsheet import
ed
failed.'
);
$this
->
outputFormatted
(
'Spreadsheet import failed.'
);
}
}
$this
->
spreadsheetImportRepository
->
update
(
$spreadsheetImport
);
$this
->
spreadsheetImportRepository
->
update
(
$spreadsheetImport
);
}
else
{
}
else
{
$this
->
outputFormatted
(
'
There is no spreadsheet importing
in queue.'
);
$this
->
outputFormatted
(
'
No spreadsheet import
in queue.'
);
}
}
}
}
/**
/**
* Cleanup previous spreadsheet imports
by specific time (defined by settings)
* Cleanup previous spreadsheet imports
. Threashold defined in settings.
*/
*/
public
function
cleanupCommand
()
{
public
function
cleanupCommand
()
{
$cleanupImport
FromPreviousDay
=
$this
->
settings
[
'cleanupImportFromPreviousDay'
]
;
$cleanupImport
sThreasholdDays
=
intval
(
$this
->
settings
[
'cleanupImportsThreasholdDays'
])
;
$cleanupFromDate
=
new
\DateTime
();
$cleanupFromDate
=
new
\DateTime
();
$cleanupFromDate
->
sub
(
new
\DateInterval
(
'P'
.
$cleanupImport
FromPreviousDay
.
'D'
));
$cleanupFromDate
->
sub
(
new
\DateInterval
(
'P'
.
$cleanupImport
sThreasholdDays
.
'D'
));
$oldSpreadsheetImports
=
$this
->
spreadsheetImportRepository
->
findPreviousImportsBySpecificDate
(
$cleanupFromDate
);
$oldSpreadsheetImports
=
$this
->
spreadsheetImportRepository
->
findPreviousImportsBySpecificDate
(
$cleanupFromDate
);
if
(
$oldSpreadsheetImports
->
count
()
>
0
)
{
if
(
$oldSpreadsheetImports
->
count
()
>
0
)
{
/** @var SpreadsheetImport $oldSpreadsheetImport */
/** @var SpreadsheetImport $oldSpreadsheetImport */
...
...
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
9af7082e
...
@@ -137,8 +137,8 @@ class SpreadsheetImportService {
...
@@ -137,8 +137,8 @@ class SpreadsheetImportService {
public
function
getObjectByRow
(
$number
)
{
public
function
getObjectByRow
(
$number
)
{
$domain
=
$this
->
domain
;
$domain
=
$this
->
domain
;
$newObject
=
new
$domain
;
$newObject
=
new
$domain
;
// Plus one to skip the headings
$sheet
=
$this
->
getFileActiveSheet
();
$sheet
=
$this
->
getFileActiveSheet
();
// Plus one to skip the headings
$row
=
$sheet
->
getRowIterator
(
$number
+
1
,
$number
+
1
)
->
current
();
$row
=
$sheet
->
getRowIterator
(
$number
+
1
,
$number
+
1
)
->
current
();
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
return
$newObject
;
return
$newObject
;
...
@@ -151,74 +151,62 @@ class SpreadsheetImportService {
...
@@ -151,74 +151,62 @@ class SpreadsheetImportService {
$totalInserted
=
0
;
$totalInserted
=
0
;
$totalUpdated
=
0
;
$totalUpdated
=
0
;
$totalDeleted
=
0
;
$totalDeleted
=
0
;
$totalSkipped
=
0
;
$processedObjectIds
=
array
();
$objectIds
=
array
();
$domain
=
$this
->
domain
;
$objectRepository
=
$this
->
getDomainRepository
();
$objectRepository
=
$this
->
getDomainRepository
();
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$domain
);
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$
this
->
domain
);
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$sheet
=
$this
->
getFileActiveSheet
();
$sheet
=
$this
->
getFileActiveSheet
();
$
numberOfRecordsToPersist
=
$this
->
settings
[
'numberOfRecordsToPersist'
]
;
$
persistRecordsChunkSize
=
intval
(
$this
->
settings
[
'persistRecordsChunkSize'
])
;
$
i
=
0
;
$
totalCount
=
0
;
/** @var \PHPExcel_Worksheet_Row $row */
/** @var \PHPExcel_Worksheet_Row $row */
foreach
(
$sheet
->
getRowIterator
(
2
)
as
$row
)
{
foreach
(
$sheet
->
getRowIterator
(
2
)
as
$row
)
{
$totalCount
++
;
$object
=
$this
->
findObjectByIdentifierPropertiesPerRow
(
$identifierProperties
,
$row
);
$object
=
$this
->
findObjectByIdentifierPropertiesPerRow
(
$identifierProperties
,
$row
);
if
(
is_object
(
$object
))
{
if
(
is_object
(
$object
))
{
$
o
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
$
processedO
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
if
(
$this
->
spreadsheetImport
->
isUpdating
())
{
if
(
$this
->
spreadsheetImport
->
isUpdating
())
{
$this
->
setObjectPropertiesByRow
(
$object
,
$row
);
$this
->
setObjectPropertiesByRow
(
$object
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$object
);
$validationResult
=
$objectValidator
->
validate
(
$object
);
if
(
$validationResult
->
hasErrors
())
{
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
continue
;
}
}
$objectRepository
->
update
(
$object
);
$objectRepository
->
update
(
$object
);
$totalUpdated
++
;
$totalUpdated
++
;
$i
++
;
}
else
{
}
else
{
$totalSkipped
++
;
continue
;
continue
;
}
}
}
elseif
(
$this
->
spreadsheetImport
->
isInserting
())
{
}
elseif
(
$this
->
spreadsheetImport
->
isInserting
())
{
$newObject
=
new
$domain
;
$newObject
=
new
$
this
->
domain
;
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$newObject
);
$validationResult
=
$objectValidator
->
validate
(
$newObject
);
if
(
$validationResult
->
hasErrors
())
{
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
continue
;
}
}
$objectRepository
->
add
(
$newObject
);
$objectRepository
->
add
(
$newObject
);
$
o
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$
processedO
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$totalInserted
++
;
$totalInserted
++
;
$i
++
;
}
else
{
}
else
{
$totalSkipped
++
;
continue
;
continue
;
}
}
if
(
$
i
>=
$numberOfRecordsToPersist
)
{
if
(
$
totalCount
%
$persistRecordsChunkSize
===
0
)
{
$this
->
persistenceManager
->
persistAll
();
$this
->
persistenceManager
->
persistAll
();
$i
=
0
;
}
}
}
}
$deleteCount
=
0
;
// remove objects which are not exist on the spreadsheet
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$
o
bjectIds
);
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$
processedO
bjectIds
);
foreach
(
$notExistingObjects
as
$object
)
{
foreach
(
$notExistingObjects
as
$object
)
{
$objectRepository
->
remove
(
$object
);
$objectRepository
->
remove
(
$object
);
$totalDeleted
++
;
if
(
++
$deleteCount
%
$persistRecordsChunkSize
===
0
)
{
$i
++
;
if
(
$i
>=
$numberOfRecordsToPersist
)
{
$this
->
persistenceManager
->
persistAll
();
$this
->
persistenceManager
->
persistAll
();
$i
=
0
;
}
}
}
}
}
}
$this
->
persistenceManager
->
persistAll
();
$this
->
spreadsheetImport
->
setTotalInserted
(
$totalInserted
);
$this
->
spreadsheetImport
->
setTotalInserted
(
$totalInserted
);
$this
->
spreadsheetImport
->
setTotalUpdated
(
$totalUpdated
);
$this
->
spreadsheetImport
->
setTotalUpdated
(
$totalUpdated
);
$this
->
spreadsheetImport
->
setTotalSkipped
(
$totalCount
-
$totalInserted
-
$totalUpdated
);
$this
->
spreadsheetImport
->
setTotalDeleted
(
$totalDeleted
);
$this
->
spreadsheetImport
->
setTotalDeleted
(
$totalDeleted
);
$this
->
spreadsheetImport
->
setTotalSkipped
(
$totalSkipped
);
}
}
/**
/**
...
...
Configuration/Settings.yaml
View file @
9af7082e
WE
:
WE
:
SpreadsheetImport
:
SpreadsheetImport
:
cleanupImport
FromPreviousDay
:
365
cleanupImport
sThreasholdDays
:
365
numberOfRecordsToPersist
:
100
persistRecordsChunkSize
:
100
Configuration/Settings.yaml.example
View file @
9af7082e
WE:
WE:
SpreadsheetImport:
SpreadsheetImport:
cleanupImport
FromPreviousDay
: 365
cleanupImport
sThreasholdDays
: 365
numberOfRecordsToPersist
: 100
persistRecordsChunkSize
: 100
default:
default:
domain: WE\Sample\Domain\Model\User
domain: WE\Sample\Domain\Model\User
arguments:
arguments:
...
...
Resources/Private/Translations/de/Main.xlf
View file @
9af7082e
...
@@ -44,10 +44,10 @@
...
@@ -44,10 +44,10 @@
<source>
Ungültige Daten. Dieser Record wird nicht übersprungen.
</source>
<source>
Ungültige Daten. Dieser Record wird nicht übersprungen.
</source>
</trans-unit>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<source>
Vorschau
Zeile
</source>
<source>
Zeile
</source>
</trans-unit>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<source>
Spreadsheet Imports
</source>
<source>
Importe
</source>
</trans-unit>
</trans-unit>
<!-- Status -->
<!-- Status -->
...
...
Resources/Private/Translations/en/Main.xlf
View file @
9af7082e
...
@@ -44,10 +44,10 @@
...
@@ -44,10 +44,10 @@
<source>
Invalid data. This record will be skipped.
</source>
<source>
Invalid data. This record will be skipped.
</source>
</trans-unit>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<source>
Preview r
ecord
</source>
<source>
R
ecord
</source>
</trans-unit>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<source>
Spreadsheet
Imports
</source>
<source>
Imports
</source>
</trans-unit>
</trans-unit>
<!-- Status -->
<!-- Status -->
...
...
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