mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
use Config\Database;
|
|
use App\Models\Catalogo\IdentificadorIsknModel;
|
|
|
|
class CatalogoLibroAsignarIskn extends BaseCommand
|
|
{
|
|
protected $group = 'custom';
|
|
protected $name = 'catalogo:libro-asignar-iskn';
|
|
protected $description = 'Asigna ISKN directamente en la base de datos a los libros que no lo tienen.';
|
|
|
|
public function run(array $params)
|
|
{
|
|
$db = Database::connect();
|
|
$modelISKN = new IdentificadorIsknModel();
|
|
|
|
// Obtener todos los libros sin ISKN
|
|
$libros = $db->table('catalogo_libros')
|
|
->select('id')
|
|
->where('iskn IS NULL')
|
|
->where('deleted_at IS NULL')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
if (empty($libros)) {
|
|
CLI::write('No hay libros sin ISKN por asignar.', 'green');
|
|
return;
|
|
}
|
|
|
|
CLI::write('Asignando ISKN a ' . count($libros) . ' libros...', 'yellow');
|
|
|
|
$i = 1;
|
|
foreach ($libros as $libro) {
|
|
$iskn = $modelISKN->newIskn();
|
|
|
|
if ($iskn !== null) {
|
|
$db->table('catalogo_libros')
|
|
->where('id', $libro['id'])
|
|
->update(['iskn' => $iskn]);
|
|
|
|
CLI::write("[{$i}] ISKN '{$iskn}' asignado a libro ID {$libro['id']}", 'cyan');
|
|
} else {
|
|
CLI::error("[{$i}] No se pudo generar ISKN para libro ID {$libro['id']}");
|
|
}
|
|
|
|
$i++;
|
|
}
|
|
|
|
CLI::write('Proceso finalizado.', 'green');
|
|
}
|
|
}
|