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
7d3a4216
Commit
7d3a4216
authored
Aug 31, 2018
by
Van
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(all): Sync ok (except for locale, to make manually); Pb slug fixed ;
parent
2201e247
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
107 additions
and
68 deletions
+107
-68
FluxController.php
src/Controller/Backend/FluxController.php
+0
-1
FluxType.php
src/Form/FluxType.php
+1
-1
Synchronisation.php
src/Synchronisation/Synchronisation.php
+8
-10
TourinsoftExtension.php
src/TourinsoftExtension.php
+0
-1
ContentTypeFile.php
src/Utils/ContentTypeFile.php
+17
-15
Data.php
src/Utils/Data.php
+44
-29
Parser.php
src/Utils/Parser.php
+9
-6
Schema.php
src/Utils/Schema.php
+28
-5
No files found.
src/Controller/Backend/FluxController.php
View file @
7d3a4216
...
...
@@ -77,7 +77,6 @@ class FluxController extends BackendBase
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$flux
=
$form
->
getData
();
$flux
->
setCreatedAt
(
new
\DateTimeImmutable
());
$flux
->
setEnabled
(
true
);
$this
->
getRepository
(
Flux
::
class
)
->
save
(
$flux
);
...
...
src/Form/FluxType.php
View file @
7d3a4216
...
...
@@ -7,7 +7,6 @@ use Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux;
use
Bolt\Translation\Translator
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\Extension\Core\Type\CheckboxType
;
use
Symfony\Component\Form\Extension\Core\Type\CollectionType
;
use
Symfony\Component\Form\Extension\Core\Type\TextType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
...
...
@@ -60,6 +59,7 @@ class FluxType extends AbstractType
[
'label'
=>
false
,
'config'
=>
$options
[
'config'
],
'read_only'
=>
$options
[
'edit_mode'
],
'edit_mode'
=>
$options
[
'edit_mode'
]
])
->
add
(
...
...
src/Synchronisation/Synchronisation.php
View file @
7d3a4216
...
...
@@ -3,16 +3,14 @@
namespace
Bolt\Extension\Appolo\Tourinsoft\Synchronisation
;
use
Bolt\Application
;
use
Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux
;
use
Bolt\Extension\Appolo\Tourinsoft\Storage\Repository\FluxRepository
;
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\Schema
;
use
Bolt\Provider\DatabaseSchemaServiceProvider
;
use
Bolt\Provider\ExtensionServiceProvider
;
use
Bolt\Provider\StorageServiceProvider
;
use
Bolt\Storage\Database\Schema\Table\ContentType
;
class
Synchronisation
{
...
...
@@ -29,9 +27,11 @@ class Synchronisation
*/
private
$application
;
/**
* Synchornisation constructor.
* @param array $config
* @param Application $application
* @param Flux $flux
* @throws \Exception
*/
...
...
@@ -46,7 +46,7 @@ class Synchronisation
}
/**
*
*
Synchronisation flux
*/
public
function
sync
()
{
$options
=
$this
->
config
[
'tourinsoft'
];
...
...
@@ -61,18 +61,14 @@ class Synchronisation
$file
=
new
ContentTypeFile
(
$this
->
application
,
$this
->
flux
,
$fields
,
$options
);
$file
->
updateInFile
();
$this
->
application
[
'config'
]
->
initialize
();
$this
->
application
->
register
(
new
StorageServiceProvider
());
$this
->
application
->
register
(
new
DatabaseSchemaServiceProvider
());
// Sync database
$schema
=
new
Schema
(
$this
->
application
);
$schema
->
update
();
$schema
->
update
Step1
();
// Add data
$data
=
new
Data
(
$this
->
application
,
$this
->
flux
->
getCode
(),
$arrayStream
,
$options
);
$data
->
insert
();
}
/**
...
...
@@ -89,6 +85,7 @@ class Synchronisation
// Sync database
$schema
=
new
Schema
(
$this
->
application
);
$schema
->
update
();
$schema
->
updateStep1
();
}
}
\ No newline at end of file
src/TourinsoftExtension.php
View file @
7d3a4216
...
...
@@ -175,7 +175,6 @@ class TourinsoftExtension extends SimpleExtension
$sync
->
sync
();
}
// Return a message to the console
$event
->
output
->
writeln
(
"<comment>Synchronisation terminée</comment>"
);
}
...
...
src/Utils/ContentTypeFile.php
View file @
7d3a4216
...
...
@@ -52,12 +52,12 @@ class ContentTypeFile
$data
=
[
$this
->
flux
->
getCode
()
=>
[
'name'
=>
ucfirst
(
$this
->
flux
->
getTitle
()),
'singular_name'
=>
ucfirst
(
$this
->
flux
->
getContentType
()),
'slug'
=>
strtolower
(
$this
->
flux
->
getTitle
()),
'singular_name'
=>
ucfirst
(
$this
->
flux
->
getContentType
()),
'singular_slug'
=>
strtolower
(
$this
->
flux
->
getContentType
()),
'fields'
=>
$this
->
getFields
(),
'record_template'
=>
strtolower
(
'tourinsoft/'
.
$this
->
flux
->
getCode
()
.
'/
'
.
$this
->
flux
->
getContentType
()
.
'
.twig'
),
'listing_template'
=>
strtolower
(
'tourinsoft/'
.
$this
->
flux
->
getCode
()
.
'/listing_
'
.
$this
->
flux
->
getContentType
()
.
'
.twig'
),
'record_template'
=>
strtolower
(
'tourinsoft/'
.
$this
->
flux
->
getCode
()
.
'/
record
.twig'
),
'listing_template'
=>
strtolower
(
'tourinsoft/'
.
$this
->
flux
->
getCode
()
.
'/listing_
record
.twig'
),
'viewless'
=>
$this
->
flux
->
isViewless
(),
'searchable'
=>
$this
->
flux
->
isSearchable
()
]
...
...
@@ -69,7 +69,8 @@ class ContentTypeFile
/**
* Delete content type in file
*/
public
function
deleteInFile
()
{
public
function
deleteInFile
()
{
$this
->
updateOrDelete
([],
true
);
}
...
...
@@ -79,6 +80,12 @@ class ContentTypeFile
private
function
getFields
()
{
$fields
=
[];
$fields
[
'locale'
]
=
[
'type'
=>
'locale'
,
'group'
=>
'content'
];
foreach
(
$this
->
keys
as
$key
)
{
$fields
[
strtolower
(
$key
)]
=
[
'type'
=>
'text'
,
...
...
@@ -88,12 +95,7 @@ class ContentTypeFile
];
}
$fields
[
'locale'
]
=
[
'type'
=>
'locale'
,
'group'
=>
'content'
];
$fields
[
'slug'
]
=
[
$fields
[
'slug'
]
=
[
'type'
=>
'slug'
,
'uses'
=>
'nomoffre'
];
...
...
@@ -106,12 +108,11 @@ class ContentTypeFile
'type'
=>
'hidden'
];
$fields
[
$slugKey
]
=
[
'type'
=>
'
locale_data
'
,
'type'
=>
'
hidden
'
,
'index'
=>
true
];
}
}
return
$fields
;
}
...
...
@@ -119,7 +120,8 @@ class ContentTypeFile
* @param array $data
* @param bool $delete
*/
private
function
updateOrDelete
(
array
$data
=
[],
$delete
=
false
)
{
private
function
updateOrDelete
(
array
$data
=
[],
$delete
=
false
)
{
/** @var YamlFile $file */
$file
=
$this
->
application
[
'filesystem'
]
->
getFile
(
strtolower
(
'config://contenttypes.yml'
));
if
(
$file
->
exists
())
{
...
...
@@ -132,7 +134,6 @@ class ContentTypeFile
}
$yamlData
+=
$data
;
}
$file
->
dump
(
$yamlData
,
[
'inline'
=>
4
]);
}
}
...
...
@@ -141,7 +142,8 @@ class ContentTypeFile
* @param $key
* @return mixed
*/
private
function
getFieldLabel
(
$key
)
{
private
function
getFieldLabel
(
$key
)
{
if
(
empty
(
$this
->
options
)
||
empty
(
$this
->
options
[
'field_mapping'
])
||
...
...
src/Utils/Data.php
View file @
7d3a4216
...
...
@@ -32,9 +32,10 @@ class Data
* @param Application $application
* @param string $contentType
* @param array $arrayStream
* @param array $options
*/
public
function
__construct
(
Application
$application
,
$contentType
=
''
,
array
$arrayStream
=
[],
array
$options
=
[])
{
public
function
__construct
(
Application
$application
,
$contentType
=
''
,
array
$arrayStream
=
[],
array
$options
=
[])
{
$this
->
application
=
$application
;
$this
->
arrayStream
=
$arrayStream
;
$this
->
contentType
=
$contentType
;
...
...
@@ -44,12 +45,12 @@ class Data
/**
* Insert data in database
*/
public
function
insert
()
{
public
function
insert
()
{
$this
->
deleteData
();
$items
=
$this
->
getFormattedItems
();
$contentType
=
$this
->
getContentType
();
// $contentType['status'] = 'published';
// $contentType['status'] = 'published';
foreach
(
$items
as
$k
=>
$item
)
{
$this
->
application
[
'storage.request.save'
]
->
action
(
$item
,
$contentType
,
null
,
null
,
null
,
null
);
...
...
@@ -59,17 +60,21 @@ class Data
/**
* Delete data from contenttype table
*/
private
function
deleteData
()
{
private
function
deleteData
()
{
$contentTypeRepository
=
$this
->
application
[
'storage'
]
->
getRepository
(
$this
->
contentType
);
$deleteFieldQuery
=
$contentTypeRepository
->
createQueryBuilder
()
->
delete
(
$contentTypeRepository
->
getTableName
());
$deleteFieldQuery
=
$contentTypeRepository
->
createQueryBuilder
()
->
delete
(
$contentTypeRepository
->
getTableName
());
$deleteFieldQuery
->
execute
();
}
/**
* @return mixed
*/
private
function
getContentType
()
{
private
function
getContentType
()
{
return
$this
->
application
[
'storage'
]
->
getContentType
(
$this
->
contentType
);
}
...
...
@@ -77,46 +82,53 @@ class Data
* @return array
* @throws \Exception
*/
private
function
getFormattedItems
()
{
private
function
getFormattedItems
()
{
$items
=
[];
if
(
!
empty
(
$defaultStream
=
$this
->
arrayStream
[
$this
->
options
[
'default_locale'
]]))
{
if
(
!
empty
(
$defaultStream
=
$this
->
arrayStream
[
$this
->
options
[
'default_locale'
]]))
{
foreach
(
$defaultStream
[
'value'
]
as
$item
)
{
$data
=
[];
foreach
(
$item
as
$k
=>
$v
)
{
$key
=
strtolower
(
$k
);
$data
[
$key
]
=
$v
;
}
$data
[
'title'
]
=
$data
[
'syndicobjectname'
];
$data
[
'slug'
]
=
Slugify
::
create
()
->
slugify
(
$data
[
'nomoffre'
]);
$data
[
'status'
]
=
'published'
;
$data
[
'datepublish'
]
=
new
\DateTimeImmutable
();
$this
->
getTranslatedItem
(
$data
);
array_push
(
$items
,
$data
);
}
}
return
$items
;
}
private
function
getTranslatedItem
(
array
&
$data
=
[])
{
if
(
!
empty
(
$this
->
options
[
'locales'
]))
{
/**
* @param array $data
*/
private
function
getTranslatedItem
(
array
&
$data
=
[])
{
if
(
!
empty
(
$this
->
options
[
'locales'
]))
{
foreach
(
$this
->
options
[
'locales'
]
as
$locale
)
{
$dataKey
=
strtolower
(
$locale
)
.
'data'
;
$slugKey
=
strtolower
(
$locale
)
.
'slug'
;
$dataKey
=
strtolower
(
$locale
)
.
'data'
;
$slugKey
=
strtolower
(
$locale
)
.
'slug'
;
if
(
$locale
==
$this
->
options
[
'default_locale'
])
{
if
(
$locale
==
$this
->
options
[
'default_locale'
])
{
$data
[
$dataKey
]
=
json_encode
([]);
$data
[
$slugKey
]
=
''
;
$data
[
$slugKey
]
=
Slugify
::
create
()
->
slugify
(
$data
[
'nomoffre'
])
;
}
else
{
$dataLocale
=
$this
->
getDataForLocale
(
$locale
,
$data
[
'syndicobjectid'
]);
$data
[
$dataKey
]
=
json_encode
(
$dataLocale
);
$data
[
$slugKey
]
=
$dataLocale
[
'slug'
];
$dataLocale
=
$this
->
getDataForLocales
(
$locale
,
$data
[
'syndicobjectid'
]);
if
(
!
empty
(
$dataLocale
))
{
$data
[
$dataKey
]
=
json_encode
(
$dataLocale
);
$data
[
$slugKey
]
=
$dataLocale
[
'slug'
];
}
else
{
$data
[
$dataKey
]
=
json_encode
([]);
$data
[
$slugKey
]
=
Slugify
::
create
()
->
slugify
(
$data
[
'nomoffre'
]);
}
}
}
}
}
...
...
@@ -126,22 +138,24 @@ class Data
* @param $id
* @return array
*/
private
function
getDataForLocale
(
$locale
,
$id
)
{
if
(
!
empty
(
$defaultStream
=
$this
->
arrayStream
[
$locale
]))
{
private
function
getDataForLocales
(
$locale
,
$id
)
{
if
(
!
empty
(
$defaultStream
=
$this
->
arrayStream
[
$locale
]))
{
foreach
(
$defaultStream
[
'value'
]
as
$item
)
{
if
(
$item
[
'SyndicObjectID'
]
===
$id
)
{
if
(
$item
[
'SyndicObjectID'
]
===
$id
)
{
$data
=
[];
foreach
(
$item
as
$k
=>
$v
)
{
$key
=
strtolower
(
$k
);
$data
[
$key
]
=
$v
;
}
$data
[
'title'
]
=
$data
[
'syndicobjectname'
];
$data
[
'slug'
]
=
Slugify
::
create
()
->
slugify
(
$data
[
'nomoffre'
]);
$data
[
'slug'
]
=
Slugify
::
create
()
->
slugify
(
$
locale
.
'-'
.
$
data
[
'nomoffre'
]);
return
$data
;
}
}
}
return
[];
}
}
\ No newline at end of file
src/Utils/Parser.php
View file @
7d3a4216
...
...
@@ -26,10 +26,13 @@ class Parser
throw
new
\Exception
(
'La configuration n\'est pas valide.'
);
}
$this
->
options
=
$options
;
foreach
(
$options
[
'keys'
]
as
$locale
=>
$key
)
{
$url
=
$options
[
'url'
]
.
$options
[
'ot_key'
]
.
'/'
.
$key
.
'/Objects?$format=JSON'
;
$this
->
getStreamAsArray
(
$url
,
$locale
);
if
(
empty
(
$key
))
{
$this
->
arrayStream
[
$locale
]
=
null
;
}
else
{
$url
=
$options
[
'url'
]
.
$options
[
'ot_key'
]
.
'/'
.
$key
.
'/Objects?$format=JSON'
;
$this
->
getStreamAsArray
(
$url
,
$locale
);
}
}
}
...
...
@@ -47,7 +50,6 @@ class Parser
}
}
}
return
$keys
;
}
...
...
@@ -62,15 +64,16 @@ class Parser
* @param string $url
* @param string $locale
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Exception
*/
protected
function
getStreamAsArray
(
$url
,
$locale
)
{
protected
function
getStreamAsArray
(
$url
,
$locale
)
{
$client
=
new
Client
();
$res
=
$client
->
request
(
'GET'
,
$url
);
if
(
$res
->
getStatusCode
()
!==
200
)
{
throw
new
\Exception
(
'Le flux n\'a pu être récupéré.'
);
}
try
{
$this
->
arrayStream
[
$locale
]
=
json_decode
(
$res
->
getBody
(),
true
);
}
catch
(
\Exception
$e
)
{
...
...
src/Utils/Schema.php
View file @
7d3a4216
...
...
@@ -3,6 +3,8 @@
namespace
Bolt\Extension\Appolo\Tourinsoft\Utils
;
use
Bolt\Application
;
use
Bolt\Provider\DatabaseSchemaServiceProvider
;
use
Bolt\Provider\StorageServiceProvider
;
class
Schema
{
...
...
@@ -20,11 +22,31 @@ class Schema
$this
->
application
=
$application
;
}
public
function
update
()
{
public
function
updateStep1
()
{
$this
->
application
[
'config'
]
->
initialize
();
$this
->
application
->
register
(
new
StorageServiceProvider
());
$this
->
application
->
register
(
new
DatabaseSchemaServiceProvider
());
$output
=
$this
->
schemaManager
()
->
update
();
$this
->
session
()
->
set
(
'dbupdate_result'
,
$output
->
getResponseStrings
());
}
// $this->application['schema']->isUpdateRequired();
// $this->application['schema']->check();
$output
=
$this
->
application
[
'schema'
]
->
update
();
$this
->
application
[
'session'
]
->
set
(
'dbupdate_result'
,
$output
->
getResponseStrings
());
/**
* @return \Bolt\Storage\Database\Schema\Manager
*/
protected
function
schemaManager
()
{
return
$this
->
application
[
'schema'
];
}
/**
* Returns the session.
*
* @return \Symfony\Component\HttpFoundation\Session\Session
*/
protected
function
session
()
{
return
$this
->
application
[
'session'
];
}
}
\ No newline at end of file
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