Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GoGoCarto
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
17
Issues
17
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pixel Humain
GoGoCarto
Commits
2082b4c9
Commit
2082b4c9
authored
Feb 11, 2019
by
Sebastian Castro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import progress bar
parent
de38aece
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
179 additions
and
34 deletions
+179
-34
src/Biopen/GeoDirectoryBundle/Command/ImportSourceCommand.php
...Biopen/GeoDirectoryBundle/Command/ImportSourceCommand.php
+2
-5
src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportDynamicAdminController.php
...yBundle/Controller/Admin/ImportDynamicAdminController.php
+16
-4
src/Biopen/GeoDirectoryBundle/Controller/ImportController.php
...Biopen/GeoDirectoryBundle/Controller/ImportController.php
+28
-22
src/Biopen/GeoDirectoryBundle/Document/Import.php
src/Biopen/GeoDirectoryBundle/Document/Import.php
+65
-1
src/Biopen/GeoDirectoryBundle/Resources/config/routing-import.yml
...en/GeoDirectoryBundle/Resources/config/routing-import.yml
+7
-1
src/Biopen/GeoDirectoryBundle/Resources/views/admin/pages/import/import-progress.html.twig
...ources/views/admin/pages/import/import-progress.html.twig
+46
-0
src/Biopen/GeoDirectoryBundle/Services/ElementImportService.php
...open/GeoDirectoryBundle/Services/ElementImportService.php
+15
-1
No files found.
src/Biopen/GeoDirectoryBundle/Command/ImportSourceCommand.php
View file @
2082b4c9
...
...
@@ -34,13 +34,10 @@ class ImportSourceCommand extends GoGoAbstractCommand
return
;
}
$this
->
log
(
'Updating source '
.
$import
->
getSourceName
()
.
' for project '
.
$input
->
getArgument
(
'dbname'
)
.
' begins...'
);
$this
->
log
(
'Downloading the data...'
);
$importService
=
$this
->
getContainer
()
->
get
(
'biopen.element_import'
);
$dataToImport
=
$importService
->
importJson
(
$import
,
true
);
$this
->
log
(
'Data downloaded. '
.
count
(
$dataToImport
)
.
' elements to import...'
);
$result
=
$importService
->
importData
(
$dataToImport
,
$import
,
$this
->
logger
);
$result
=
$importService
->
startImport
(
$import
);
$this
->
log
(
$result
);
}
catch
(
\
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
$this
->
error
(
"Source: "
.
$import
->
getSourceName
()
.
" - "
.
$e
->
getMessage
());
}
}
...
...
src/Biopen/GeoDirectoryBundle/Controller/Admin/ImportDynamicAdminController.php
View file @
2082b4c9
...
...
@@ -5,6 +5,7 @@ namespace Biopen\GeoDirectoryBundle\Controller\Admin;
use
Sonata\AdminBundle\Controller\CRUDController
as
Controller
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\HttpFoundation\Request
;
use
Biopen\GeoDirectoryBundle\Document\ImportState
;
class
ImportDynamicAdminController
extends
Controller
{
...
...
@@ -12,12 +13,23 @@ class ImportDynamicAdminController extends Controller
{
$object
=
$this
->
admin
->
getSubject
();
$object
->
setCurrState
(
ImportState
::
Started
);
$object
->
setCurrMessage
(
"En attente..."
);
$em
=
$this
->
get
(
'doctrine_mongodb'
)
->
getManager
();
$em
->
persist
(
$object
);
$em
->
flush
();
$this
->
get
(
'biopen.async'
)
->
callCommand
(
'app:elements:importSource'
,
[
$object
->
getId
()]);
$this
->
addFlash
(
'sonata_flash_success'
,
"Les éléments sont en cours d'importation. Cela peut prendre plusieurs minutes."
);
// $result = $this->get('biopen.element_import')->importJson($object);
// $this->addFlash('sonata_flash_success', $result);
// $result = $this->get('biopen.element_import')->importJson($object);
$redirectionUrl
=
$this
->
admin
->
generateUrl
(
'edit'
,
[
'id'
=>
$object
->
getId
()]);
$stateUrl
=
$this
->
generateUrl
(
'biopen_import_state'
,
[
'id'
=>
$object
->
getId
()]);
return
$this
->
redirect
(
$this
->
admin
->
generateUrl
(
'edit'
,
[
'id'
=>
$object
->
getId
()]));
return
$this
->
render
(
'@BiopenAdmin/pages/import/import-progress.html.twig'
,
[
'import'
=>
$object
,
'redirectUrl'
=>
$redirectionUrl
,
'stateUrl'
=>
$stateUrl
]);
}
}
\ No newline at end of file
src/Biopen/GeoDirectoryBundle/Controller/ImportController.php
View file @
2082b4c9
...
...
@@ -25,26 +25,32 @@ use joshtronic\LoremIpsum;
class
ImportController
extends
Controller
{
public
function
generateRandom
(
$nombre
,
$generateVote
=
false
)
{
$lastElementCreated
=
$this
->
get
(
'biopen.random_creation_service'
)
->
generate
(
$nombre
,
$generateVote
);
return
new
Response
(
'Elements générés'
);
}
// public function importCsvAction($fileName, $geocode)
// {
// $this->get('biopen.element_import')->importCsv($fileName, $geocode);
// return new Response('Elements importés');
// }
public
function
availableOptionsAction
()
{
$options
=
$this
->
get
(
'doctrine_mongodb'
)
->
getManager
()
->
getRepository
(
'BiopenGeoDirectoryBundle:Option'
)
->
findAll
();
$bottomOptions
=
array_filter
(
$options
,
function
(
$option
)
{
return
$option
->
getSubcategoriesCount
()
==
0
;});
$optionsNames
=
array_map
(
function
(
$option
)
{
return
$option
->
getNameWithParent
();
},
$bottomOptions
);
return
new
Response
(
join
(
'<br>'
,
$optionsNames
));
}
public
function
generateRandom
(
$nombre
,
$generateVote
=
false
)
{
$lastElementCreated
=
$this
->
get
(
'biopen.random_creation_service'
)
->
generate
(
$nombre
,
$generateVote
);
return
new
Response
(
'Elements générés'
);
}
public
function
availableOptionsAction
()
{
$options
=
$this
->
get
(
'doctrine_mongodb'
)
->
getManager
()
->
getRepository
(
'BiopenGeoDirectoryBundle:Option'
)
->
findAll
();
$bottomOptions
=
array_filter
(
$options
,
function
(
$option
)
{
return
$option
->
getSubcategoriesCount
()
==
0
;});
$optionsNames
=
array_map
(
function
(
$option
)
{
return
$option
->
getNameWithParent
();
},
$bottomOptions
);
return
new
Response
(
join
(
'<br>'
,
$optionsNames
));
}
public
function
currStateAction
(
$id
)
{
$em
=
$this
->
get
(
'doctrine_mongodb'
)
->
getManager
();
$import
=
$em
->
getRepository
(
'BiopenGeoDirectoryBundle:Import'
)
->
find
(
$id
);
$responseArray
=
array
(
"state"
=>
$import
->
getCurrState
(),
"message"
=>
$import
->
getCurrMessage
()
);
$response
=
new
Response
(
json_encode
(
$responseArray
));
$response
->
headers
->
set
(
'Content-Type'
,
'application/json'
);
return
$response
;
}
}
src/Biopen/GeoDirectoryBundle/Document/Import.php
View file @
2082b4c9
...
...
@@ -7,6 +7,15 @@ use Symfony\Component\HttpFoundation\File\File;
use
Vich\UploaderBundle\Mapping\Annotation
as
Vich
;
use
Biopen\CoreBundle\Document\AbstractFile
;
abstract
class
ImportState
{
const
Failed
=
"failed"
;
const
Started
=
"started"
;
const
Downloading
=
"downloading"
;
const
InProgress
=
"in_progress"
;
const
Completed
=
"completed"
;
}
/**
* @MongoDB\Document
* @Vich\Uploadable
...
...
@@ -63,7 +72,18 @@ class Import extends AbstractFile
/**
* @MongoDB\ReferenceMany(targetDocument="Biopen\CoreBundle\Document\GoGoLog", cascade={"all"})
*/
private
$logs
;
private
$logs
;
/**
*
* @MongoDB\Field(type="string")
*/
private
$currState
;
/**
* @MongoDB\Field(type="string")
*/
private
$currMessage
;
public
function
__construct
()
{
$this
->
logs
=
new
\
Doctrine\Common\Collections\ArrayCollection
();;
...
...
@@ -254,4 +274,48 @@ class Import extends AbstractFile
usort
(
$logs
,
function
(
$a
,
$b
)
{
return
$b
->
getCreatedAt
()
->
getTimestamp
()
-
$a
->
getCreatedAt
()
->
getTimestamp
();
});
return
$logs
;
}
/**
* Set currState
*
* @param string $currState
* @return $this
*/
public
function
setCurrState
(
$currState
)
{
$this
->
currState
=
$currState
;
return
$this
;
}
/**
* Get currState
*
* @return string $currState
*/
public
function
getCurrState
()
{
return
$this
->
currState
;
}
/**
* Set currMessage
*
* @param string $currMessage
* @return $this
*/
public
function
setCurrMessage
(
$currMessage
)
{
$this
->
currMessage
=
$currMessage
;
return
$this
;
}
/**
* Get currMessage
*
* @return string $currMessage
*/
public
function
getCurrMessage
()
{
return
$this
->
currMessage
;
}
}
src/Biopen/GeoDirectoryBundle/Resources/config/routing-import.yml
View file @
2082b4c9
...
...
@@ -4,4 +4,10 @@ biopen_element_import_csv:
biopen_element_import_available_options
:
path
:
/available-options
defaults
:
{
_controller
:
BiopenGeoDirectoryBundle
:
Import
:
availableOptions
}
\ No newline at end of file
defaults
:
{
_controller
:
BiopenGeoDirectoryBundle
:
Import
:
availableOptions
}
biopen_import_state
:
path
:
/import/{id}/state
defaults
:
{
_controller
:
BiopenGeoDirectoryBundle
:
Import
:
currState
}
requirements
:
methods
:
GET
\ No newline at end of file
src/Biopen/GeoDirectoryBundle/Resources/views/admin/pages/import/import-progress.html.twig
0 → 100644
View file @
2082b4c9
{%
extends
'@BiopenAdmin/pages/page_layout.html.twig'
%}
{%
block
page_title
%}
Importation de
{{
import.sourceName
}}{%
endblock
%}
{%
block
page_content
%}
<div
class=
"alert alert-default text-center progress-container"
>
<div
class=
"curr-message"
>
En attente...
</div>
<a
style=
"display:none"
class=
"redirect-url"
href=
"
{{
redirectUrl
}}
"
>
Retourner à l'import
</a>
</div>
<script>
$
(
document
).
ready
(
function
()
{
function
checkCurrState
(
$logId
)
{
$
.
ajax
({
method
:
'
get
'
,
url
:
'
{{
stateUrl
}}
'
,
success
:
function
(
data
,
status
,
object
)
{
$
(
'
.curr-message
'
).
html
(
data
.
message
);
var
currClass
=
'
alert-default
'
;
switch
(
data
.
state
)
{
case
'
downloading
'
:
currClass
=
'
alert-info
'
;
break
;
case
'
in_progress
'
:
currClass
=
'
alert-info
'
;
break
;
case
'
failed
'
:
currClass
=
'
alert-danger
'
;
break
;
case
'
completed
'
:
currClass
=
'
alert-success
'
;
break
;
}
$
(
'
.progress-container
'
).
removeClass
(
"
alert-info
"
).
addClass
(
currClass
);
if
(
data
.
state
==
"
failed
"
||
data
.
state
==
'
completed
'
)
{
$
(
'
.redirect-url
'
).
show
();
}
else
{
setTimeout
(
checkCurrState
,
1000
);
}
},
});
}
checkCurrState
();
});
</script>
{%
endblock
%}
src/Biopen/GeoDirectoryBundle/Services/ElementImportService.php
View file @
2082b4c9
...
...
@@ -17,6 +17,7 @@ use Biopen\GeoDirectoryBundle\Document\UserRoles;
use
Biopen\GeoDirectoryBundle\Document\PostalAddress
;
use
Biopen\GeoDirectoryBundle\Document\ElementUrl
;
use
Biopen\GeoDirectoryBundle\Document\ElementImage
;
use
Biopen\GeoDirectoryBundle\Document\ImportState
;
use
Biopen\CoreBundle\Document\GoGoLog
;
use
Biopen\CoreBundle\Document\GoGoLogType
;
...
...
@@ -57,6 +58,10 @@ class ElementImportService
}
public
function
startImport
(
$import
)
{
$import
->
setCurrState
(
ImportState
::
Downloading
);
$import
->
setCurrMessage
(
"Téléchargement des données en cours... Veuillez patienter..."
);
$this
->
em
->
persist
(
$import
);
$this
->
em
->
flush
();
if
(
$import
->
getUrl
())
return
$this
->
importJson
(
$import
);
else
return
$this
->
importCsv
(
$import
);
}
...
...
@@ -154,10 +159,13 @@ class ElementImportService
->
getQuery
()
->
execute
();
}
$import
->
setCurrState
(
ImportState
::
InProgress
);
// processing each data
foreach
(
$data
as
$row
)
{
try
{
$import
->
setCurrMessage
(
"Importation des données "
.
$i
.
'/'
.
$size
.
' traitées'
);
$this
->
createElementFromArray
(
$row
,
$import
);
$i
++
;
}
...
...
@@ -178,12 +186,14 @@ class ElementImportService
$this
->
em
->
clear
();
// After flush, we need to get again the import from the DB to avoid doctrine raising errors
$import
=
$this
->
em
->
getRepository
(
'BiopenGeoDirectoryBundle:ImportDynamic'
)
->
find
(
$import
->
getId
());
$this
->
em
->
persist
(
$import
);
}
}
$this
->
em
->
flush
();
$this
->
em
->
clear
();
$import
=
$this
->
em
->
getRepository
(
'BiopenGeoDirectoryBundle:ImportDynamic'
)
->
find
(
$import
->
getId
());
$import
=
$this
->
em
->
getRepository
(
'BiopenGeoDirectoryBundle:ImportDynamic'
)
->
find
(
$import
->
getId
());
$this
->
em
->
persist
(
$import
);
$countElemenDeleted
=
0
;
if
(
$import
->
isDynamicImport
())
...
...
@@ -229,6 +239,10 @@ class ElementImportService
$log
=
new
GoGoLog
(
$logType
,
$result
);
$log
->
setSubcontent
(
implode
(
'</br>'
,
$this
->
errorsMessages
));
$import
->
addLog
(
$log
);
$import
->
setCurrState
(
$totalErrors
>
(
$size
/
4
)
?
ImportState
::
Failed
:
ImportState
::
Completed
);
$import
->
setCurrMessage
(
$result
.
'</br></br>'
.
implode
(
'</br>'
,
$this
->
errorsMessages
));
$this
->
em
->
flush
();
return
$result
;
...
...
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