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
f686dc55
Commit
f686dc55
authored
Oct 27, 2016
by
Simon Gadient
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[IMP] Argument support for static parameter assignment
refs KIME-4583
parent
70f31a75
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
39 deletions
+150
-39
Classes/WE/SpreadsheetImport/Domain/Model/SpreadsheetImport.php
...s/WE/SpreadsheetImport/Domain/Model/SpreadsheetImport.php
+29
-1
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
+76
-31
Configuration/Testing/Settings.yaml
Configuration/Testing/Settings.yaml
+1
-6
Migrations/Mysql/Version20161026173055.php
Migrations/Mysql/Version20161026173055.php
+43
-0
Tests/Functional/Fixtures/ImportTarget.php
Tests/Functional/Fixtures/ImportTarget.php
+1
-1
No files found.
Classes/WE/SpreadsheetImport/Domain/Model/SpreadsheetImport.php
View file @
f686dc55
...
...
@@ -47,6 +47,12 @@ class SpreadsheetImport {
*/
protected
$mapping
=
''
;
/**
* @var string
* @ORM\Column(type="text")
*/
protected
$arguments
=
''
;
/**
* @var boolean
*/
...
...
@@ -141,7 +147,11 @@ class SpreadsheetImport {
* @return array
*/
public
function
getMapping
()
{
return
unserialize
(
$this
->
mapping
);
$mapping
=
unserialize
(
$this
->
mapping
);
if
(
!
is_array
(
$mapping
))
{
$mapping
=
array
();
}
return
$mapping
;
}
/**
...
...
@@ -151,6 +161,24 @@ class SpreadsheetImport {
$this
->
mapping
=
serialize
(
$mapping
);
}
/**
* @return array
*/
public
function
getArguments
()
{
return
unserialize
(
$this
->
arguments
);
}
/**
* @param string|array $arguments
*/
public
function
setArguments
(
$arguments
)
{
if
(
is_array
(
$arguments
))
{
$this
->
arguments
=
serialize
(
$arguments
);
}
else
{
$this
->
arguments
=
$arguments
;
}
}
/**
* @return boolean
*/
...
...
Classes/WE/SpreadsheetImport/SpreadsheetImportService.php
View file @
f686dc55
...
...
@@ -26,9 +26,9 @@ class SpreadsheetImportService {
protected
$spreadsheetImport
;
/**
* @var
array
* @var
string
*/
protected
$
context
;
protected
$
domain
;
/**
* @var array
...
...
@@ -52,12 +52,6 @@ class SpreadsheetImportService {
*/
protected
$reflectionService
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Resource\ResourceManager
*/
protected
$resourceManager
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Persistence\PersistenceManagerInterface
...
...
@@ -70,6 +64,12 @@ class SpreadsheetImportService {
*/
protected
$objectManager
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Property\PropertyMapper
*/
protected
$propertyMapper
;
/**
* @param \WE\SpreadsheetImport\Domain\Model\SpreadsheetImport $spreadsheetImport
*
...
...
@@ -77,7 +77,7 @@ class SpreadsheetImportService {
*/
public
function
init
(
SpreadsheetImport
$spreadsheetImport
)
{
$this
->
spreadsheetImport
=
$spreadsheetImport
;
$this
->
context
=
$this
->
settings
[
$spreadsheetImport
->
getContext
()
];
$this
->
domain
=
$this
->
settings
[
$spreadsheetImport
->
getContext
()][
'domain'
];
$this
->
initDomainMappingProperties
();
$this
->
initColumnPropertyMapping
();
...
...
@@ -89,9 +89,9 @@ class SpreadsheetImportService {
*/
private
function
initDomainMappingProperties
()
{
$this
->
mappingProperties
=
array
();
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
context
[
'domain'
]
,
Mapping
::
class
);
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
domain
,
Mapping
::
class
);
foreach
(
$properties
as
$property
)
{
$this
->
mappingProperties
[
$property
]
=
$this
->
reflectionService
->
getPropertyAnnotation
(
$this
->
context
[
'domain'
]
,
$property
,
Mapping
::
class
);
$this
->
mappingProperties
[
$property
]
=
$this
->
reflectionService
->
getPropertyAnnotation
(
$this
->
domain
,
$property
,
Mapping
::
class
);
}
}
...
...
@@ -109,6 +109,13 @@ class SpreadsheetImportService {
* Adds additional mapping properties to the domain mapping properties retrieved by annotations. This increases
* flexibility for dynamic property mapping.
*
* This was implemented for the single use case to support the Flow package Radmiraal.CouchDB
*
* Note: Those additional property configurations are not persisted and need to be added after each initialization
* of the service. The persisted mappings in the SpreadsheetImport object only contain the property without any
* configuration. Therefore, the import works but only for the default setters and without identifiers. To support
* all, the additional mapping properties need to be persisted together with the mappings.
*
* @param array $additionalMappingProperties
*/
public
function
addAdditionalMappingProperties
(
array
$additionalMappingProperties
)
{
...
...
@@ -123,19 +130,12 @@ class SpreadsheetImportService {
}
/**
* @param string $context
*
* @return array
*/
private
function
getDomainMappingIdentifierProperties
()
{
$domainMappingProperties
=
array
();
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
context
[
'domain'
],
Mapping
::
class
);
foreach
(
$properties
as
$property
)
{
/** @var Mapping $mapping */
$mapping
=
$this
->
reflectionService
->
getPropertyAnnotation
(
$this
->
context
[
'domain'
],
$property
,
Mapping
::
class
);
if
(
$mapping
->
identifier
)
{
$domainMappingProperties
[
$property
]
=
$mapping
;
}
}
return
$domainMappingProperties
;
public
function
getArgumentsByContext
(
$context
)
{
return
$this
->
settings
[
$context
][
'arguments'
];
}
/**
...
...
@@ -166,7 +166,7 @@ class SpreadsheetImportService {
* @return object
*/
public
function
getObjectByRow
(
$number
)
{
$domain
=
$this
->
context
[
'domain'
]
;
$domain
=
$this
->
domain
;
$newObject
=
new
$domain
;
// Plus one to skip the headings
$file
=
$this
->
spreadsheetImport
->
getFile
()
->
createTemporaryLocalCopy
();
...
...
@@ -185,7 +185,7 @@ class SpreadsheetImportService {
$totalDeleted
=
0
;
$totalSkipped
=
0
;
$objectIds
=
array
();
$domain
=
$this
->
context
[
'domain'
]
;
$domain
=
$this
->
domain
;
$objectRepository
=
$this
->
getDomainRepository
();
$identifierProperties
=
$this
->
getDomainMappingIdentifierProperties
();
$file
=
$this
->
spreadsheetImport
->
getFile
()
->
createTemporaryLocalCopy
();
...
...
@@ -232,13 +232,29 @@ class SpreadsheetImportService {
* @return \TYPO3\Flow\Persistence\RepositoryInterface
*/
private
function
getDomainRepository
()
{
$domainClassName
=
$this
->
context
[
'domain'
]
;
$domainClassName
=
$this
->
domain
;
$repositoryClassName
=
preg_replace
(
array
(
'/\\\Model\\\/'
,
'/$/'
),
array
(
'\\Repository\\'
,
'Repository'
),
$domainClassName
);
/** @var RepositoryInterface $repository */
$repository
=
$this
->
objectManager
->
get
(
$repositoryClassName
);
return
$repository
;
}
/**
* @return array
*/
private
function
getDomainMappingIdentifierProperties
()
{
$domainMappingProperties
=
array
();
$properties
=
$this
->
reflectionService
->
getPropertyNamesByAnnotation
(
$this
->
domain
,
Mapping
::
class
);
foreach
(
$properties
as
$property
)
{
/** @var Mapping $mapping */
$mapping
=
$this
->
reflectionService
->
getPropertyAnnotation
(
$this
->
domain
,
$property
,
Mapping
::
class
);
if
(
$mapping
->
identifier
)
{
$domainMappingProperties
[
$property
]
=
$mapping
;
}
}
return
$domainMappingProperties
;
}
/**
* @param array $identifierProperties
* @param \PHPExcel_Worksheet_Row $row
...
...
@@ -277,10 +293,10 @@ class SpreadsheetImportService {
}
/**
* @param object $
newO
bject
* @param object $
o
bject
* @param \PHPExcel_Worksheet_Row $row
*/
private
function
setObjectPropertiesByRow
(
$
newO
bject
,
$row
)
{
private
function
setObjectPropertiesByRow
(
$
o
bject
,
$row
)
{
$domainMappingProperties
=
$this
->
mappingProperties
;
/** @var \PHPExcel_Cell $cell */
foreach
(
$row
->
getCellIterator
()
as
$cell
)
{
...
...
@@ -288,11 +304,40 @@ class SpreadsheetImportService {
if
(
array_key_exists
(
$column
,
$this
->
columnPropertyMapping
))
{
$properties
=
$this
->
columnPropertyMapping
[
$column
];
foreach
(
$properties
as
$property
)
{
if
(
array_key_exists
(
$property
,
$domainMappingProperties
))
{
/** @var Mapping $mapping */
$mapping
=
$domainMappingProperties
[
$property
];
$setter
=
empty
(
$mapping
->
setter
)
?
'set'
.
ucfirst
(
$property
)
:
$mapping
->
setter
;
$newObject
->
$setter
(
$cell
->
getValue
());
}
else
{
$setter
=
'set'
.
ucfirst
(
$property
);
}
$object
->
$setter
(
$cell
->
getValue
());
}
}
}
$this
->
setObjectArgumentProperties
(
$object
);
}
/**
* @param $object
*/
private
function
setObjectArgumentProperties
(
$object
)
{
$contextArguments
=
$this
->
getArgumentsByContext
(
$this
->
spreadsheetImport
->
getContext
());
if
(
is_array
(
$contextArguments
))
{
$arguments
=
$this
->
spreadsheetImport
->
getArguments
();
foreach
(
$contextArguments
as
$contextArgument
)
{
$name
=
$contextArgument
[
'name'
];
if
(
array_key_exists
(
$name
,
$arguments
))
{
if
(
array_key_exists
(
'domain'
,
$contextArgument
))
{
$value
=
$this
->
propertyMapper
->
convert
(
$arguments
[
$name
],
$contextArgument
[
'domain'
]);
}
else
{
$value
=
$arguments
[
$name
];
}
}
else
{
$value
=
array_key_exists
(
'default'
,
$contextArgument
)
?
$contextArgument
[
'default'
]
:
NULL
;
}
$setter
=
'set'
.
ucfirst
(
$name
);
$object
->
$setter
(
$value
);
}
}
}
...
...
Configuration/Testing/Settings.yaml
View file @
f686dc55
...
...
@@ -2,9 +2,4 @@ WE:
SpreadsheetImport
:
testing
:
domain
:
WE\SpreadsheetImport\Tests\Functional\Fixtures\ImportTarget
Configuration
:
userProfileType
:
setter
:
convertUserProfileTypeBySysValue
value
:
'
swisscomGRB'
privacy
:
value
:
'
private'
arguments
:
~
Migrations/Mysql/Version20161026173055.php
0 → 100644
View file @
f686dc55
<?php
namespace
TYPO3\Flow\Persistence\Doctrine\Migrations
;
use
Doctrine\DBAL\Migrations\AbstractMigration
;
use
Doctrine\DBAL\Schema\Schema
;
/**
* Add arguments property for serialized values
*/
class
Version20161026173055
extends
AbstractMigration
{
/**
* @return string
*/
public
function
getDescription
()
{
return
''
;
}
/**
* @param Schema $schema
* @return void
*/
public
function
up
(
Schema
$schema
)
{
$this
->
abortIf
(
$this
->
connection
->
getDatabasePlatform
()
->
getName
()
!=
'mysql'
,
'Migration can only be executed safely on "mysql".'
);
$this
->
addSql
(
'ALTER TABLE we_spreadsheetimport_domain_model_spreadsheetimport ADD arguments LONGTEXT NOT NULL'
);
$this
->
addSql
(
'ALTER TABLE we_spreadsheetimport_domain_model_spreadsheetimport ADD CONSTRAINT FK_19518FA38C9F3610 FOREIGN KEY (file) REFERENCES typo3_flow_resource_resource (persistence_object_identifier)'
);
}
/**
* @param Schema $schema
* @return void
*/
public
function
down
(
Schema
$schema
)
{
$this
->
abortIf
(
$this
->
connection
->
getDatabasePlatform
()
->
getName
()
!=
'mysql'
,
'Migration can only be executed safely on "mysql".'
);
$this
->
addSql
(
'ALTER TABLE we_spreadsheetimport_domain_model_spreadsheetimport DROP FOREIGN KEY FK_19518FA38C9F3610'
);
$this
->
addSql
(
'ALTER TABLE we_spreadsheetimport_domain_model_spreadsheetimport DROP arguments'
);
}
}
Tests/Functional/Fixtures/ImportTarget.php
View file @
f686dc55
...
...
@@ -50,7 +50,7 @@ class ImportTarget implements SpreadsheetImportTargetInterface {
* @param string $id
*/
public
function
setRawId
(
$id
)
{
$this
->
id
=
sprintf
(
"%05d"
,
$id
);
$this
->
id
=
sprintf
(
'%05d'
,
$id
);
}
/**
...
...
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