Bladeren bron

Liaison utilisateur/point de vente (UserPointSale) des données existantes via migration

Adaptation de la recherche des utilisateurs pour uniquement se baser sur UserPointSale
dev
Guillaume Bourgeois 5 jaren geleden
bovenliggende
commit
79249a86d3
2 gewijzigde bestanden met toevoegingen van 52 en 10 verwijderingen
  1. +1
    -10
      common/models/UserSearch.php
  2. +51
    -0
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php

+ 1
- 10
common/models/UserSearch.php Bestand weergeven

@@ -90,16 +90,7 @@ class UserSearch extends User
if(isset($this->id_point_sale) && $this->id_point_sale) {
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ;
if($pointSale->restricted_access) {
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
else {
$query->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $this->id_point_sale]
)->groupBy('user.id') ;
}
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
if(isset($this->inactive) && $this->inactive) {

+ 51
- 0
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php Bestand weergeven

@@ -0,0 +1,51 @@
<?php

use yii\db\Migration;

class m190226_084104_lien_utilisateur_point_de_vente extends Migration
{
public function up()
{
$producersArray = \common\models\Producer::find()->all() ;
foreach($producersArray as $producer) {
$pointsSaleArray = common\models\PointSale::find()
->where([
'id_producer' => $producer->id
])
->all();
foreach($pointsSaleArray as $pointSale) {
$usersArray = common\models\User::find()->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $pointSale->id]
)
->groupBy('user.id')
->all();
foreach($usersArray as $user) {
$userPointSale = \common\models\UserPointSale::find()
->where([
'id_user' => $user->id,
'id_point_sale' => $pointSale->id
])->one() ;
if(!$userPointSale) {
$userPointSale = new \common\models\UserPointSale() ;
$userPointSale->id_user = $user->id ;
$userPointSale->id_point_sale = $pointSale->id ;
$userPointSale->save() ;
}
}
}
}
}

public function down()
{
echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
return false;
}
}

Laden…
Annuleren
Opslaan