- Ajout de l'import des societes

This commit is contained in:
Vincent BRIDIER 2019-10-16 09:32:54 +02:00
parent 52edd61675
commit edb97bf945
2 changed files with 47 additions and 3 deletions

View file

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Models\Societe;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
@ -203,8 +204,23 @@ class ImportArcadiaFiles extends Command
// ---- Suppression du fichier
Storage::disk('arcadia')->delete($filename);
}
// TODO : Import des sociétés
}elseif (substr($filename, 0, 11) == "DAM_SOCIETE") {
foreach ($fileContent->dam as $row) {
$record = Societe::where('id', $row->codSociete)->first();
if($record){ // Update record
$record->libelle = $row->nomSociete;
$record->save();
}else{ // Insert new record
$record = new Societe();
$record->id = $row->codSociete;
$record->libelle = $row->nomSociete;
$record->save();
}
}
// ---- Suppression du fichier
Storage::disk('arcadia')->delete($filename);
}
$bar->advance();
}

View file

@ -257,7 +257,35 @@ class ImportMedia extends Command
//Storage::disk('arcadia')->delete($filename);
}
// TODO : Import de l'association des sociétés
// ---- Traitement de l'association media <-> societe
$files = File::glob(storage_path('export_arcadia') . "/DAM_ASSO_SOCIETE_*.*");
$this->line("-> Import du fichier DAM_ASSO_SOCIETE");
foreach ($files as $filename) {
$path = explode("/", $filename);
$filename = $path[count($path) - 1];
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- traitement du fichier
$bar = $this->output->createProgressBar(count($fileContent->mediaassosociete)-1);
$bar->start();
foreach ($fileContent->mediaassosociete as $row) {
$record = Media::where('arcadia_id', $row->codeVisuel)->first();
if ($record) {
// attache la societe au média
$record->societes()->attach($row->codSociete);
} else {
$this->line("\nDAM_ASSO_SOCIETE : le media n°" . $row->codeVisuel . " n'existe pas");
}
$bar->advance();
}
$bar->finish();
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
}
$this->line("");
$this->info('Fin du traitement');