Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
Tourinsoft
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bolt Extensions
Tourinsoft
Commits
a4a35e57
Commit
a4a35e57
authored
May 11, 2018
by
Frédéric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Insert data
parent
3edcd00c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
4 deletions
+93
-4
Synchronisation.php
src/Synchronisation/Synchronisation.php
+6
-0
ContentTypeFile.php
src/Utils/ContentTypeFile.php
+4
-4
Data.php
src/Utils/Data.php
+76
-0
Parser.php
src/Utils/Parser.php
+7
-0
No files found.
src/Synchronisation/Synchronisation.php
View file @
a4a35e57
...
@@ -5,6 +5,7 @@ namespace Bolt\Extension\Appolo\Tourinsoft\Synchronisation;
...
@@ -5,6 +5,7 @@ namespace Bolt\Extension\Appolo\Tourinsoft\Synchronisation;
use
Bolt\Application
;
use
Bolt\Application
;
use
Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux
;
use
Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\ContentTypeFile
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\ContentTypeFile
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Data
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Parser
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Parser
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Schema
;
use
Bolt\Extension\Appolo\Tourinsoft\Utils\Schema
;
...
@@ -49,6 +50,7 @@ class Synchronisation
...
@@ -49,6 +50,7 @@ class Synchronisation
// Parse tourinsoft flux
// Parse tourinsoft flux
$parser
=
new
Parser
(
$options
);
$parser
=
new
Parser
(
$options
);
$keys
=
$parser
->
getKeys
();
$keys
=
$parser
->
getKeys
();
$arrayStream
=
$parser
->
getArrayStream
();
// Write in contenttypes.yml file
// Write in contenttypes.yml file
$file
=
new
ContentTypeFile
(
$this
->
application
,
$this
->
flux
->
getContentType
(),
$keys
,
$options
);
$file
=
new
ContentTypeFile
(
$this
->
application
,
$this
->
flux
->
getContentType
(),
$keys
,
$options
);
...
@@ -57,6 +59,10 @@ class Synchronisation
...
@@ -57,6 +59,10 @@ class Synchronisation
// Sync database
// Sync database
$schema
=
new
Schema
(
$this
->
application
);
$schema
=
new
Schema
(
$this
->
application
);
$schema
->
update
();
$schema
->
update
();
// Add data
$data
=
new
Data
(
$this
->
application
,
$this
->
flux
->
getContentType
(),
$arrayStream
);
$data
->
insert
();
}
}
/**
/**
...
...
src/Utils/ContentTypeFile.php
View file @
a4a35e57
...
@@ -74,16 +74,16 @@ class ContentTypeFile
...
@@ -74,16 +74,16 @@ class ContentTypeFile
$fields
=
[];
$fields
=
[];
foreach
(
$this
->
keys
as
$key
)
{
foreach
(
$this
->
keys
as
$key
)
{
$fields
[
$key
]
=
[
$fields
[
strtolower
(
$key
)
]
=
[
'type'
=>
'text'
,
'type'
=>
'text'
,
'label'
=>
$this
->
getFieldLabel
(
$key
)
'label'
=>
$this
->
getFieldLabel
(
$key
),
'readonly'
=>
true
];
];
}
}
$fields
[
'slug'
]
=
[
$fields
[
'slug'
]
=
[
'type'
=>
'slug'
,
'type'
=>
'slug'
,
'uses'
=>
'SyndicObjectID'
,
'uses'
=>
[
'syndicobjectid'
]
'group'
=>
'meta'
];
];
return
$fields
;
return
$fields
;
...
...
src/Utils/Data.php
View file @
a4a35e57
...
@@ -2,7 +2,82 @@
...
@@ -2,7 +2,82 @@
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
use
Bolt\Application
;
use
Bolt\Storage\Entity\Builder
;
class
Data
class
Data
{
{
/**
* @var Application
*/
private
$application
;
/**
* @var array
*/
private
$arrayStream
;
/**
* @var string
*/
private
$contentType
;
/**
* Data constructor.
* @param Application $application
* @param string $contentType
* @param array $arrayStream
*/
public
function
__construct
(
Application
$application
,
$contentType
=
''
,
array
$arrayStream
=
[])
{
$this
->
application
=
$application
;
$this
->
arrayStream
=
$arrayStream
;
$this
->
contentType
=
$contentType
;
}
/**
* Insert data in database
*/
public
function
insert
()
{
$this
->
deleteData
();
$items
=
$this
->
getFormattedItems
();
foreach
(
$items
as
$k
=>
$item
)
{
$this
->
application
[
'storage.request.save'
]
->
action
(
$item
,
$this
->
getContentType
(),
null
,
null
,
null
,
null
);
}
}
/**
* Delete data from contenttype table
*/
private
function
deleteData
()
{
$contentTypeRepository
=
$this
->
application
[
'storage'
]
->
getRepository
(
$this
->
contentType
);
$deleteFieldQuery
=
$contentTypeRepository
->
createQueryBuilder
()
->
delete
(
$contentTypeRepository
->
getTableName
());
$deleteFieldQuery
->
execute
();
}
/**
* @return mixed
*/
private
function
getContentType
()
{
return
$this
->
application
[
'storage'
]
->
getContentType
(
$this
->
contentType
);
}
/**
* @return array
*/
private
function
getFormattedItems
()
{
$items
=
[];
foreach
(
$this
->
arrayStream
[
'value'
]
as
$item
)
{
$data
=
[];
foreach
(
$item
as
$k
=>
$v
)
{
$key
=
strtolower
(
$k
);
$data
[
$key
]
=
$v
;
}
$data
[
'status'
]
=
'published'
;
$data
[
'date_publish'
]
=
new
\DateTimeImmutable
();
array_push
(
$items
,
$data
);
}
return
$items
;
}
}
}
\ No newline at end of file
src/Utils/Parser.php
View file @
a4a35e57
...
@@ -52,6 +52,13 @@ class Parser
...
@@ -52,6 +52,13 @@ class Parser
}
}
/**
/**
* @return array
*/
public
function
getArrayStream
()
{
return
$this
->
arrayStream
;
}
/**
* @throws \Exception
* @throws \Exception
*/
*/
protected
function
getStreamAsArray
()
{
protected
function
getStreamAsArray
()
{
...
...
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