added logic to auto-populate the hrd_username from station_callsign
这个提交包含在:
父节点
09bdac5428
当前提交
ee989de988
共有 1 个文件被更改,包括 21 次插入 和 4 次删除
|
|
@ -1,14 +1,14 @@
|
||||||
<?php
|
<?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
|
* This adds the hrdlog username to the station profile as this is needed
|
||||||
* for special callsigns
|
* for special callsigns
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Migration_hrdlog_username extends CI_Migration {
|
class Migration_hrdlog_username extends CI_Migration
|
||||||
|
{
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
if (!$this->db->field_exists('hrdlog_username', 'station_profile')) {
|
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);
|
$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()
|
public function down()
|
||||||
|
|
@ -25,4 +42,4 @@ class Migration_hrdlog_username extends CI_Migration {
|
||||||
$this->dbforge->drop_column('station_profile', 'hrdlog_username');
|
$this->dbforge->drop_column('station_profile', 'hrdlog_username');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用