added logic to auto-populate the hrd_username from station_callsign

pull/2846/head
HB9HIL 2023-12-16 09:37:45 +01:00
rodzic 09bdac5428
commit ee989de988
1 zmienionych plików z 21 dodań i 4 usunięć

Wyświetl plik

@ -1,14 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');
/*
* This adds the hrdlog username to the station profile as this is needed
* for special callsigns
*/
class Migration_hrdlog_username extends CI_Migration {
class Migration_hrdlog_username extends CI_Migration
{
public function up()
{
if (!$this->db->field_exists('hrdlog_username', 'station_profile')) {
@ -17,6 +17,23 @@ class Migration_hrdlog_username extends CI_Migration {
);
$this->dbforge->add_column('station_profile', $fields);
}
// SELECT all rows where hrdlog_code is not empty
$this->db->where("(hrdlog_code IS NOT NULL AND hrdlog_code != '')");
$query = $this->db->get('station_profile');
$rows = $query->result();
// Iterate through all selected rows
foreach ($rows as $row) {
// Extract the username using the regex pattern
$regex = '/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/';
preg_match($regex, $row->station_callsign, $matches);
$username = $matches[3];
// Update the row with the extracted username
$this->db->where('station_id', $row->station_id);
$this->db->update('station_profile', array('hrdlog_username' => $username));
}
}
public function down()
@ -25,4 +42,4 @@ class Migration_hrdlog_username extends CI_Migration {
$this->dbforge->drop_column('station_profile', 'hrdlog_username');
}
}
}
}