Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
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
1
Merge Requests
1
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
agplv3
kohinos-tav
Commits
ac119167
Commit
ac119167
authored
Jul 04, 2021
by
Julien Jorry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix import
parent
4ee144e4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
38 deletions
+80
-38
ImportAdmin.php
src/Admin/ImportAdmin.php
+2
-0
ImportController.php
src/Controller/ImportController.php
+41
-37
Import.php
src/Entity/Import.php
+5
-0
Version20210704090118.php
src/Migrations/Version20210704090118.php
+31
-0
import.html.twig
templates/themes/kohinos/admin/import.html.twig
+1
-1
No files found.
src/Admin/ImportAdmin.php
View file @
ac119167
...
...
@@ -70,6 +70,7 @@ class ImportAdmin extends AbstractAdmin
->
add
(
'nbentityadded'
,
null
,
[
'label'
=>
'Lignes correctes'
])
->
add
(
'nbentityerror'
,
null
,
[
'label'
=>
'Lignes en erreurs'
])
->
add
(
'media'
,
null
,
[
'label'
=>
'Fichier'
])
->
add
(
'test'
,
null
,
[
'label'
=>
'Test ?'
])
->
add
(
'_action'
,
null
,
[
'actions'
=>
[
'show'
=>
[],
...
...
@@ -84,6 +85,7 @@ class ImportAdmin extends AbstractAdmin
$showMapper
->
with
(
'Import'
)
->
add
(
'createdAt'
)
->
add
(
'test'
)
->
add
(
'user'
)
->
add
(
'type'
)
->
add
(
'media'
)
...
...
src/Controller/ImportController.php
View file @
ac119167
...
...
@@ -91,28 +91,25 @@ class ImportController extends CRUDController
$media
=
$import
->
getMedia
();
$type
=
$import
->
getType
();
$this
->
sendemail
=
(
bool
)
$import
->
getSendemail
();
$this
->
test
=
(
bool
)
$import
->
getTest
();
if
(
!
$this
->
test
)
{
// Sauvegarder l'import en base de données avant l'essai d'import
$this
->
em
->
persist
(
$import
);
$this
->
em
->
flush
();
$idimport
=
$import
->
getId
();
}
// Sauvegarder l'import en base de données avant l'essai d'import
$this
->
em
->
persist
(
$import
);
$this
->
em
->
flush
();
$idimport
=
$import
->
getId
();
$this
->
importFromCSV
(
$type
,
$media
);
if
(
!
$this
->
test
)
{
$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
))
{
if
(
$this
->
test
)
{
...
...
@@ -321,7 +318,7 @@ class ImportController extends CRUDController
// Importer les gestionnaires de comptoir s'ils existent
$groupeGestionnaire
=
$this
->
em
->
getRepository
(
Usergroup
::
class
)
->
findOneByName
(
'Comptoir'
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$groupeGestionnaire
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$
line
,
$
groupeGestionnaire
);
$comptoir
->
setGestionnaires
(
$gestionnaires
);
$this
->
addSuccess
(
$row
,
$line
,
'comptoir'
,
$this
->
translator
->
trans
(
'Comptoir ajouté : '
)
.
$nom
);
...
...
@@ -390,7 +387,7 @@ class ImportController extends CRUDController
}
// Importer les gestionnaires du groupe s'ils existent
$groupeGestionnaire
=
$this
->
em
->
getRepository
(
Usergroup
::
class
)
->
findOneByName
(
'Gestionnaire de Groupe'
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$groupeGestionnaire
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$
line
,
$
groupeGestionnaire
);
$groupe
->
setGestionnaires
(
$gestionnaires
);
$this
->
addSuccess
(
$row
,
$line
,
'groupe'
,
$this
->
translator
->
trans
(
'Groupe ajouté : '
)
.
$name
);
...
...
@@ -561,7 +558,7 @@ class ImportController extends CRUDController
}
// Importer les gestionnaires du prestataire s'ils existent
$groupeGestionnaire
=
$this
->
em
->
getRepository
(
Usergroup
::
class
)
->
findOneByName
(
'Prestataire'
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$groupeGestionnaire
);
$gestionnaires
=
$this
->
importGestionnaires
(
$row
,
$
line
,
$
groupeGestionnaire
);
$prestataire
->
setUsers
(
$gestionnaires
);
if
(
!
empty
(
$groupe
))
{
...
...
@@ -705,7 +702,7 @@ class ImportController extends CRUDController
$ville
=
array_key_exists
(
'ville'
,
$row
)
?
$row
[
'ville'
]
:
''
;
$cotisations
=
array_key_exists
(
'cotisations'
,
$row
)
?
$row
[
'cotisations'
]
:
''
;
if
(
!
(
array_key_exists
(
'email'
,
$row
)
))
{
if
(
empty
(
$email
))
{
$this
->
addError
(
$row
,
$line
,
'email'
,
$this
->
translator
->
trans
(
"La colonne 'email' est obligatoire !"
));
++
$line
;
++
$this
->
nberrors
;
...
...
@@ -717,11 +714,17 @@ class ImportController extends CRUDController
$adherent
=
$this
->
em
->
getRepository
(
Adherent
::
class
)
->
findOneBy
([
'idmlc'
=>
$idmlc
]);
}
if
(
empty
(
$adherent
))
{
$adherent
=
$this
->
em
->
getRepository
(
Adherent
::
class
)
->
findOneBy
([
'email'
=>
$email
]);
$userFound
=
$this
->
em
->
getRepository
(
User
::
class
)
->
findOneBy
([
'username'
=>
$email
]);
if
(
!
empty
(
$userFound
))
{
$adherent
=
$userFound
->
getAdherent
();
}
}
if
(
empty
(
$adherent
))
{
$adherent
=
new
Adherent
();
$adherent
->
setIdmlc
(
$idmlc
);
$user
=
$this
->
userManager
->
createUser
();
$user
->
setUsername
(
$email
);
$user
->
setEmail
(
$email
);
$user
->
setConfirmationToken
(
$this
->
tokenGenerator
->
generateToken
());
$user
->
setEnabled
(
true
);
$user
->
setPassword
(
md5
(
random_bytes
(
10
)));
...
...
@@ -808,11 +811,13 @@ class ImportController extends CRUDController
$cotisation
->
getCotisationInfos
()
->
setFin
(
DateTime
::
createFromFormat
(
'Ymd'
,
intval
(
$cotisationDetailsArray
[
1
])
.
'1231'
));
}
// $this->em->persist($cotisation);
try
{
$this
->
operationUtils
->
executeOperations
(
$cotisation
);
$this
->
addSuccess
(
$row
,
$line
,
'cotisations'
,
$this
->
translator
->
trans
(
'Cotisation(s) ajoutée(s) ligne : '
)
.
$line
);
}
catch
(
\Exception
$e
)
{
$this
->
addError
(
$row
,
$line
,
'cotisations'
,
$this
->
translator
->
trans
(
'Cotisation problème : '
)
.
$e
->
getMessage
());
if
(
!
$this
->
test
)
{
try
{
$this
->
operationUtils
->
executeOperations
(
$cotisation
);
$this
->
addSuccess
(
$row
,
$line
,
'cotisations'
,
$this
->
translator
->
trans
(
'Cotisation(s) ajoutée(s) ligne : '
)
.
$line
);
}
catch
(
\Exception
$e
)
{
$this
->
addError
(
$row
,
$line
,
'cotisations'
,
$this
->
translator
->
trans
(
'Cotisation problème : '
)
.
$e
->
getMessage
());
}
}
$this
->
addSuccess
(
$row
,
$line
,
'cotisations'
,
$this
->
translator
->
trans
(
'Cotisation(s) ajoutée(s) ligne : '
)
.
$line
);
}
...
...
@@ -836,12 +841,14 @@ class ImportController extends CRUDController
$this
->
addSuccess
(
$row
,
$line
,
'user'
,
$this
->
translator
->
trans
(
'Adhérent bien ajouté ligne : '
)
.
$line
);
++
$this
->
nbsuccess
;
$user
->
setPasswordRequestedAt
(
new
\DateTime
());
$this
->
userManager
->
updateUser
(
$user
);
if
(
$this
->
sendemail
)
{
$this
->
eventDispatcher
->
dispatch
(
MLCEvents
::
REGISTRATION_ADHERENT
,
new
UserEvent
(
$user
,
$this
->
getRequest
()));
if
(
!
$this
->
test
)
{
$this
->
userManager
->
updateUser
(
$user
);
if
(
$this
->
sendemail
)
{
$this
->
eventDispatcher
->
dispatch
(
MLCEvents
::
REGISTRATION_ADHERENT
,
new
UserEvent
(
$user
,
$this
->
getRequest
()));
}
$this
->
em
->
flush
();
$this
->
em
->
clear
();
}
$this
->
em
->
flush
();
$this
->
em
->
clear
();
}
++
$line
;
}
...
...
@@ -1039,11 +1046,8 @@ class ImportController extends CRUDController
}
}
elseif
(
$type
==
'adherent'
)
{
if
(
!
empty
(
$idNameOrEmail
))
{
// dump($idNameOrEmail);
// exit();
$userFound
=
$this
->
em
->
getRepository
(
User
::
class
)
->
findOneBy
([
'username'
=>
$idNameOrEmail
]);
if
(
!
empty
(
$userFound
))
{
// $entity = $this->em->getRepository(Adherent::class)->findOneBy(['user' => $userFound->getId()]);
$entity
=
$userFound
->
getAdherent
();
}
}
elseif
(
!
empty
(
$idmlc
))
{
...
...
@@ -1076,7 +1080,7 @@ class ImportController extends CRUDController
*
* @return User Manager created
*/
private
function
importGestionnaires
(
$row
,
Usergroup
$groupe
)
private
function
importGestionnaires
(
$row
,
$line
,
Usergroup
$groupe
)
{
$cptGestionnaire
=
1
;
$users
=
new
ArrayCollection
();
...
...
@@ -1122,7 +1126,7 @@ class ImportController extends CRUDController
$this
->
em
->
flush
();
}
}
if
(
$this
->
sendemail
)
{
if
(
!
$this
->
test
&&
$this
->
sendemail
)
{
$this
->
eventDispatcher
->
dispatch
(
MLCEvents
::
REGISTRATION_ADHERENT
,
new
UserEvent
(
$user
,
$this
->
getRequest
()));
}
++
$cptGestionnaire
;
...
...
src/Entity/Import.php
View file @
ac119167
...
...
@@ -93,6 +93,11 @@ class Import
*/
private
$sendemail
;
/**
* @var string
*
* @ORM\Column(name="test", type="boolean", nullable=false, options={"default": false})
*/
private
$test
;
public
function
__construct
()
...
...
src/Migrations/Version20210704090118.php
0 → 100644
View file @
ac119167
<?php
declare
(
strict_types
=
1
);
namespace
DoctrineMigrations
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\Migrations\AbstractMigration
;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final
class
Version20210704090118
extends
AbstractMigration
{
public
function
getDescription
()
:
string
{
return
''
;
}
public
function
up
(
Schema
$schema
)
:
void
{
// this up() migration is auto-generated, please modify it to your needs
$this
->
addSql
(
'ALTER TABLE import ADD test TINYINT(1) DEFAULT \'0\' NOT NULL'
);
}
public
function
down
(
Schema
$schema
)
:
void
{
// this down() migration is auto-generated, please modify it to your needs
$this
->
addSql
(
'ALTER TABLE import DROP test'
);
}
}
templates/themes/kohinos/admin/import.html.twig
View file @
ac119167
...
...
@@ -22,7 +22,7 @@
<li>
<a
class=
"sonata-action-element"
href=
"
{{
admin.generateUrl
(
'list'
)
}}
"
>
<i
class=
"fa fa-list"
aria-hidden=
"true"
></i>
{{
'
link_action_list'
|
trans
(
{}
,
'SonataAdminBundle'
)
}}
{{
'
Liste des imports'
|
trans
}}
</a>
</li>
</ul>
...
...
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