added autochatc database handler from DBmodel instance,
added set rootDir for Creator, added deduct numeric (unix timestamp) for datetime column, added method existsTable for Maintenance
This commit is contained in:
parent
8a3dfbe9f0
commit
877ca38c0b
@ -4,10 +4,19 @@ namespace TPsoft\DBmodel;
|
|||||||
|
|
||||||
class Creator {
|
class Creator {
|
||||||
|
|
||||||
private $dbh;
|
private DBmodel $dbh;
|
||||||
|
private string $rootDir = '';
|
||||||
|
|
||||||
public function __construct($dbh) {
|
public function __construct(?DBmodel $dbh = null) {
|
||||||
$this->dbh = $dbh;
|
if (is_null($dbh)) {
|
||||||
|
if (!is_null(DBmodel::$instance)) {
|
||||||
|
$this->dbh = DBmodel::$instance;
|
||||||
|
} else {
|
||||||
|
throw new \Exception('DB handler is null');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->dbh = $dbh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function interact() {
|
public function interact() {
|
||||||
@ -97,7 +106,7 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
|||||||
|
|
||||||
public $"."tables = array(
|
public $"."tables = array(
|
||||||
'".$entity."' => array(
|
'".$entity."' => array(
|
||||||
'name' => '".$entity."',
|
'name' => '".$tablename."',
|
||||||
'primary_key_name' => ".$primary_key_name.",
|
'primary_key_name' => ".$primary_key_name.",
|
||||||
'allow_attributes' => array(
|
'allow_attributes' => array(
|
||||||
".implode(",\n\t\t\t\t", $allowed_attributes)."
|
".implode(",\n\t\t\t\t", $allowed_attributes)."
|
||||||
@ -166,11 +175,14 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
|||||||
return $line;
|
return $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rootDir() {
|
public function rootDir(?string $dir = null) {
|
||||||
|
if (!is_null($dir)) {
|
||||||
|
$this->rootDir = $dir;
|
||||||
|
}
|
||||||
|
if (strlen($this->rootDir) > 0) return $this->rootDir;
|
||||||
return dirname(dirname(__FILE__));
|
return dirname(dirname(__FILE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -674,12 +674,12 @@ class DBmodel
|
|||||||
foreach ($data[$column] as $key => $val) {
|
foreach ($data[$column] as $key => $val) {
|
||||||
$prefix = $this->extractPrefix($val, $where_prefixes);
|
$prefix = $this->extractPrefix($val, $where_prefixes);
|
||||||
$n_val = str_replace($prefix, '', $val);
|
$n_val = str_replace($prefix, '', $val);
|
||||||
$data[$column] = $prefix . date('Y-m-d H:i:s', strtotime($n_val));
|
$data[$column] = $prefix . date('Y-m-d H:i:s', is_numeric($n_val) ? $n_val : strtotime($n_val));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$prefix = $this->extractPrefix($data[$column], $where_prefixes);
|
$prefix = $this->extractPrefix($data[$column], $where_prefixes);
|
||||||
$n_val = str_replace($prefix, '', $data[$column]);
|
$n_val = str_replace($prefix, '', $data[$column]);
|
||||||
$data[$column] = $prefix . date('Y-m-d H:i:s', strtotime($n_val));
|
$data[$column] = $prefix . date('Y-m-d H:i:s', is_numeric($n_val) ? $n_val : strtotime($n_val));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class Maintenance
|
|||||||
|
|
||||||
public string $lastMessage = '';
|
public string $lastMessage = '';
|
||||||
|
|
||||||
private DBmodel $dbh;
|
protected DBmodel $dbh;
|
||||||
|
|
||||||
public function __construct(?DBmodel $dbh)
|
public function __construct(?DBmodel $dbh)
|
||||||
{
|
{
|
||||||
@ -79,6 +79,14 @@ class Maintenance
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function existsTable($table_name)
|
||||||
|
{
|
||||||
|
return $this->testDB(
|
||||||
|
'SHOW TABLES LIKE "' . $table_name . '"',
|
||||||
|
$table_name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function checkDBTable($table_name, $definition)
|
public function checkDBTable($table_name, $definition)
|
||||||
{
|
{
|
||||||
if (strlen($table_name) <= 0) {
|
if (strlen($table_name) <= 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user