2017-08-31 10:09:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creazione dei campi per l'API (created_at e updated_at)
|
|
|
|
*/
|
|
|
|
|
2020-09-24 11:15:18 +02:00
|
|
|
use API\Response;
|
|
|
|
|
2017-08-31 10:09:06 +02:00
|
|
|
// I record precedenti vengono impostati a NULL
|
2018-09-19 15:12:20 +02:00
|
|
|
$tables = include __DIR__.'/tables.php';
|
2017-08-31 10:09:06 +02:00
|
|
|
|
2017-09-01 12:55:48 +02:00
|
|
|
foreach ($tables as $table) {
|
2018-07-03 15:05:27 +02:00
|
|
|
if ($database->tableExists($table)) {
|
2018-01-04 16:59:05 +01:00
|
|
|
$query = 'SHOW COLUMNS FROM `'.$table.'` IN `'.$database->getDatabaseName()."` WHERE Field='|field|'";
|
2017-08-31 10:09:06 +02:00
|
|
|
|
2017-09-01 12:55:48 +02:00
|
|
|
$created_at = $database->fetchArray(str_replace('|field|', 'created_at', $query));
|
|
|
|
if (empty($created_at)) {
|
|
|
|
$database->query('ALTER TABLE `'.$table.'` ADD `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP');
|
|
|
|
}
|
2017-08-31 10:09:06 +02:00
|
|
|
|
2020-09-24 11:15:18 +02:00
|
|
|
if (Response::isCompatible()) {
|
2017-09-01 12:55:48 +02:00
|
|
|
$updated_at = $database->fetchArray(str_replace('|field|', 'updated_at', $query));
|
|
|
|
if (empty($updated_at)) {
|
|
|
|
$database->query('ALTER TABLE `'.$table.'` ADD `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
|
|
|
|
}
|
2017-08-31 10:09:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|