1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-20 20:25:17 +01:00
openstamanager/update/api.php

27 lines
955 B
PHP
Raw Normal View History

<?php
/*
* Creazione dei campi per l'API (created_at e updated_at)
*/
// I record precedenti vengono impostati a NULL
2018-09-19 15:12:20 +02:00
$tables = include __DIR__.'/tables.php';
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|'";
$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');
}
2019-07-19 15:23:00 +02:00
if (API\Response::isCompatible()) {
$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');
}
}
}
}