Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
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
cooperatic-mlc
kohinos
Commits
ed1727e0
Commit
ed1727e0
authored
Sep 25, 2020
by
Mathieu Poisbeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#181: si erreur fatal/technique lors de l'import => l'affiche proprement à l'utilisateur
parent
28abaf87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
24 deletions
+54
-24
ImportController.php
src/Controller/ImportController.php
+29
-24
import_error.html.twig
templates/admin/import_error.html.twig
+25
-0
No files found.
src/Controller/ImportController.php
View file @
ed1727e0
...
...
@@ -82,9 +82,6 @@ class ImportController extends CRUDController
$this
->
sendemail
=
false
;
}
/**
* @TODO: manage the case of a fatal error (so catch the exception, and display a nice message)!
*/
public
function
createAction
()
{
$this
->
siege
=
$this
->
em
->
getRepository
(
Siege
::
class
)
->
findOneById
(
1
);
...
...
@@ -104,32 +101,40 @@ class ImportController extends CRUDController
$this
->
em
->
flush
();
$idimport
=
$import
->
getId
();
$this
->
importFromCSV
(
$type
,
$media
);
try
{
$this
->
importFromCSV
(
$type
,
$media
);
$import
=
$this
->
em
->
getRepository
(
Import
::
class
)
->
findOneById
(
$idimport
);
$import
->
setEnabled
(
true
);
$import
=
$this
->
em
->
getRepository
(
Import
::
class
)
->
findOneById
(
$idimport
);
$import
->
setEnabled
(
true
);
$import
->
setSuccess
(
json_encode
(
$this
->
success
));
$import
->
setWarnings
(
json_encode
(
$this
->
warnings
));
$import
->
setErrors
(
json_encode
(
$this
->
errors
));
$import
->
setNbentityadded
(
$this
->
nbsuccess
);
$import
->
setNbentityerror
(
$this
->
nberrors
);
$this
->
em
->
persist
(
$import
);
$this
->
em
->
flush
();
$import
->
setSuccess
(
json_encode
(
$this
->
success
));
$import
->
setWarnings
(
json_encode
(
$this
->
warnings
));
$import
->
setErrors
(
json_encode
(
$this
->
errors
));
$import
->
setNbentityadded
(
$this
->
nbsuccess
);
$import
->
setNbentityerror
(
$this
->
nberrors
);
$this
->
em
->
persist
(
$import
);
$this
->
em
->
flush
();
if
(
empty
(
$this
->
errors
))
{
$this
->
addFlash
(
'success'
,
'Import effectué avec succès !'
);
}
else
{
$this
->
addFlash
(
'error'
,
"Il y a eu des erreurs lors de l'import !"
);
if
(
empty
(
$this
->
errors
))
{
$this
->
addFlash
(
'success'
,
'Import effectué avec succès !'
);
}
else
{
$this
->
addFlash
(
'error'
,
"Il y a eu des erreurs lors de l'import !"
);
}
return
$this
->
redirect
(
$this
->
admin
->
generateUrl
(
'show'
,
array
(
'id'
=>
$import
->
getId
())));
}
catch
(
\Exception
$e
)
{
return
$this
->
renderWithExtraParams
(
'admin/import_error.html.twig'
,
[
'action'
=>
'list'
,
'error'
=>
$e
->
getMessage
(),
]);
}
return
$this
->
redirect
(
$this
->
admin
->
generateUrl
(
'show'
,
array
(
'id'
=>
$import
->
getId
())));
}
return
$this
->
renderWithExtraParams
(
'admin/import.html.twig'
,
array
(
'action'
=>
'list'
,
'form'
=>
$form
->
createView
(),
...
...
templates/admin/import_error.html.twig
0 → 100644
View file @
ed1727e0
{%
extends
base_template
%}
{%
import
_self
as
macros
%}
{%
-
block
tab_menu
-
%}
{{
knp_menu_render
(
admin.sidemenu
(
action
),
{
'currentClass'
:
'active'
,
'template'
:
get_global_template
(
'tab_menu_template'
)
}
,
'twig'
)
}}
{%
-
endblock
-
%}
{%
block
title
%}
{{
'Import de données : erreur !'
|
trans
}}
{%
endblock
%}
{%
block
navbar_title
%}
{{
block
(
'title'
)
}}
{%
endblock
%}
{%
block
content
%}
<div
class=
"px-3"
>
<h3>
Erreur lors de l'importation !
</h3>
<p><strong>
Message à transmettre à l'équipe technique :
</strong>
{{
error
}}
</p>
</div>
{%
endblock
%}
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