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
8 years ago
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
Hide 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 {
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
()
{
$currentImportingCount
=
$this
->
spreadsheetImportRepository
->
countByImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_IN_PROGRESS
);
if
(
$currentImportingCount
>
0
)
{
$this
->
outputFormatted
(
'
There is a progressing importing spreadsheet
.'
);
$this
->
outputFormatted
(
'
Previous spreadsheet import is still in progress
.'
);
$this
->
quit
();
}
/** @var SpreadsheetImport $spreadsheetImport */
...
...
@@ -67,25 +67,25 @@ class SpreadsheetImportCommandController extends CommandController {
try
{
$this
->
spreadsheetImportService
->
import
();
$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
()));
}
catch
(
Exception
$e
)
{
$spreadsheetImport
->
setImportingStatus
(
SpreadsheetImport
::
IMPORTING_STATUS_FAILED
);
$this
->
outputFormatted
(
'Spreadsheet import
ed
failed.'
);
$this
->
outputFormatted
(
'Spreadsheet import failed.'
);
}
$this
->
spreadsheetImportRepository
->
update
(
$spreadsheetImport
);
}
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
()
{
$cleanupImport
FromPreviousDay
=
$this
->
settings
[
'cleanupImportFromPreviousDay'
]
;
$cleanupImport
sThreasholdDays
=
intval
(
$this
->
settings
[
'cleanupImportsThreasholdDays'
])
;
$cleanupFromDate
=
new
\DateTime
();
$cleanupFromDate
->
sub
(
new
\DateInterval
(
'P'
.
$cleanupImport
FromPreviousDay
.
'D'
));
$cleanupFromDate
->
sub
(
new
\DateInterval
(
'P'
.
$cleanupImport
sThreasholdDays
.
'D'
));
$oldSpreadsheetImports
=
$this
->
spreadsheetImportRepository
->
findPreviousImportsBySpecificDate
(
$cleanupFromDate
);
if
(
$oldSpreadsheetImports
->
count
()
>
0
)
{
/** @var SpreadsheetImport $oldSpreadsheetImport */
...
...
This diff is collapsed.
Click to expand it.
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
9af7082e
...
...
@@ -137,8 +137,8 @@ class SpreadsheetImportService {
public
function
getObjectByRow
(
$number
)
{
$domain
=
$this
->
domain
;
$newObject
=
new
$domain
;
// Plus one to skip the headings
$sheet
=
$this
->
getFileActiveSheet
();
// Plus one to skip the headings
$row
=
$sheet
->
getRowIterator
(
$number
+
1
,
$number
+
1
)
->
current
();
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
return
$newObject
;
...
...
@@ -151,74 +151,62 @@ class SpreadsheetImportService {
$totalInserted
=
0
;
$totalUpdated
=
0
;
$totalDeleted
=
0
;
$totalSkipped
=
0
;
$objectIds
=
array
();
$domain
=
$this
->
domain
;
$processedObjectIds
=
array
();
$objectRepository
=
$this
->
getDomainRepository
();
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$domain
);
$objectValidator
=
$this
->
validatorResolver
->
getBaseValidatorConjunction
(
$
this
->
domain
);
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$sheet
=
$this
->
getFileActiveSheet
();
$
numberOfRecordsToPersist
=
$this
->
settings
[
'numberOfRecordsToPersist'
]
;
$
i
=
0
;
$
persistRecordsChunkSize
=
intval
(
$this
->
settings
[
'persistRecordsChunkSize'
])
;
$
totalCount
=
0
;
/** @var \PHPExcel_Worksheet_Row $row */
foreach
(
$sheet
->
getRowIterator
(
2
)
as
$row
)
{
$totalCount
++
;
$object
=
$this
->
findObjectByIdentifierPropertiesPerRow
(
$identifierProperties
,
$row
);
if
(
is_object
(
$object
))
{
$
o
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$object
);
$
processedO
bjectIds
[]
=
$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
;
$newObject
=
new
$
this
->
domain
;
$this
->
setObjectPropertiesByRow
(
$newObject
,
$row
);
$validationResult
=
$objectValidator
->
validate
(
$newObject
);
if
(
$validationResult
->
hasErrors
())
{
$totalSkipped
++
;
continue
;
}
$objectRepository
->
add
(
$newObject
);
$
o
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$
processedO
bjectIds
[]
=
$this
->
persistenceManager
->
getIdentifierByObject
(
$newObject
);
$totalInserted
++
;
$i
++
;
}
else
{
$totalSkipped
++
;
continue
;
}
if
(
$
i
>=
$numberOfRecordsToPersist
)
{
if
(
$
totalCount
%
$persistRecordsChunkSize
===
0
)
{
$this
->
persistenceManager
->
persistAll
();
$i
=
0
;
}
}
// remove objects which are not exist on the spreadsheet
$deleteCount
=
0
;
if
(
$this
->
spreadsheetImport
->
isDeleting
())
{
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$
o
bjectIds
);
$notExistingObjects
=
$this
->
findObjectsByExcludedIds
(
$
processedO
bjectIds
);
foreach
(
$notExistingObjects
as
$object
)
{
$objectRepository
->
remove
(
$object
);
$totalDeleted
++
;
$i
++
;
if
(
$i
>=
$numberOfRecordsToPersist
)
{
if
(
++
$deleteCount
%
$persistRecordsChunkSize
===
0
)
{
$this
->
persistenceManager
->
persistAll
();
$i
=
0
;
}
}
}
$this
->
persistenceManager
->
persistAll
();
$this
->
spreadsheetImport
->
setTotalInserted
(
$totalInserted
);
$this
->
spreadsheetImport
->
setTotalUpdated
(
$totalUpdated
);
$this
->
spreadsheetImport
->
setTotalSkipped
(
$totalCount
-
$totalInserted
-
$totalUpdated
);
$this
->
spreadsheetImport
->
setTotalDeleted
(
$totalDeleted
);
$this
->
spreadsheetImport
->
setTotalSkipped
(
$totalSkipped
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Configuration/Settings.yaml
View file @
9af7082e
WE
:
SpreadsheetImport
:
cleanupImport
FromPreviousDay
:
365
numberOfRecordsToPersist
:
100
cleanupImport
sThreasholdDays
:
365
persistRecordsChunkSize
:
100
This diff is collapsed.
Click to expand it.
Configuration/Settings.yaml.example
View file @
9af7082e
WE:
SpreadsheetImport:
cleanupImport
FromPreviousDay
: 365
numberOfRecordsToPersist
: 100
cleanupImport
sThreasholdDays
: 365
persistRecordsChunkSize
: 100
default:
domain: WE\Sample\Domain\Model\User
arguments:
...
...
This diff is collapsed.
Click to expand it.
Resources/Private/Translations/de/Main.xlf
View file @
9af7082e
...
...
@@ -44,10 +44,10 @@
<source>
Ungültige Daten. Dieser Record wird nicht übersprungen.
</source>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<source>
Vorschau
Zeile
</source>
<source>
Zeile
</source>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<source>
Spreadsheet Imports
</source>
<source>
Importe
</source>
</trans-unit>
<!-- Status -->
...
...
This diff is collapsed.
Click to expand it.
Resources/Private/Translations/en/Main.xlf
View file @
9af7082e
...
...
@@ -44,10 +44,10 @@
<source>
Invalid data. This record will be skipped.
</source>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.preview.record"
>
<source>
Preview r
ecord
</source>
<source>
R
ecord
</source>
</trans-unit>
<trans-unit
id=
"label.spreadsheet_import.list"
>
<source>
Spreadsheet
Imports
</source>
<source>
Imports
</source>
</trans-unit>
<!-- Status -->
...
...
This diff is collapsed.
Click to expand it.
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