Merge pull request #4065 from annando/dbstructure-class

There is now a Dbstructure class
This commit is contained in:
Hypolite Petovan 2017-12-14 17:48:38 -05:00 committed by GitHub
commit afbfbde112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1725 additions and 1712 deletions

View file

@ -28,6 +28,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Database\DBStructure;
require_once 'include/network.php';
require_once 'include/plugin.php';
@ -37,13 +38,20 @@ require_once 'include/pgettext.php';
require_once 'include/nav.php';
require_once 'include/identity.php';
require_once 'update.php';
require_once 'include/dbstructure.php';
define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1236);
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/**
* @brief Constants for the database update check
*/
const DB_UPDATE_NOT_CHECKED = 0; // Database check wasn't executed before
const DB_UPDATE_SUCCESSFUL = 1; // Database check was successful
const DB_UPDATE_FAILED = 2; // Database check failed
/**
* @brief Constant with a HTML line break.
@ -694,9 +702,9 @@ function update_db(App $a)
// run new update routine
// it update the structure in one call
$retval = update_structure(false, true);
$retval = DBStructure::update(false, true);
if ($retval) {
update_fail(
DBStructure::updateFail(
DB_UPDATE_VERSION,
$retval
);
@ -742,7 +750,7 @@ function run_update_function($x)
if ($retval) {
//send the administrator an e-mail
update_fail(
DBStructure::updateFail(
$x,
sprintf(t('Update %s failed. See error logs.'), $x)
);

View file

@ -1,6 +1,7 @@
<?php
use \Friendica\Core\System;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
require_once('include/datetime.php');
@ -829,12 +830,12 @@ class dba {
/**
* @brief Build the array with the table relations
*
* The array is build from the database definitions in dbstructure.php
* The array is build from the database definitions in DBStructure.php
*
* This process must only be started once, since the value is cached.
*/
private static function build_relation_data() {
$definition = db_definition();
$definition = DBStructure::definition();
foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) {

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@ use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Model\Contact;
use Friendica\Model\User;
@ -708,7 +709,7 @@ function admin_page_summary(App $a)
$warningtext = array();
if (DBM::is_result($r)) {
$showwarning = true;
$warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php include/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
$warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php scripts/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
}
// Check if github.com/friendica/master/VERSION is higher then
// the local version of Friendica. Check is opt-in, source may be master or devel branch
@ -721,12 +722,11 @@ function admin_page_summary(App $a)
}
if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) {
require_once("include/dbstructure.php");
update_structure(false, true);
DBStructure::update(false, true);
}
if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
$showwarning = true;
$warningtext[] = t('The database update failed. Please run "php include/dbstructure.php update" from the command line and have a look at the errors that might appear.');
$warningtext[] = t('The database update failed. Please run "php scripts/dbstructure.php update" from the command line and have a look at the errors that might appear.');
}
$last_worker_call = Config::get('system', 'last_poller_execution', false);
@ -1385,8 +1385,7 @@ function admin_page_dbsync(App $a)
}
if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
require_once("include/dbstructure.php");
$retval = update_structure(false, true);
$retval = DBStructure::update(false, true);
if (!$retval) {
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />";
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');

View file

@ -5,6 +5,7 @@
use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Object\Image;
$install_wizard_pass = 1;
@ -535,9 +536,7 @@ function load_database_rem($v, $i) {
}
function load_database() {
require_once("include/dbstructure.php");
$errors = update_structure(false, true);
$errors = DBStructure::update(false, true);
return $errors;
}

View file

@ -5,25 +5,26 @@
* @brief Does database updates from the command line
*/
require_once 'include/dbstructure.php';
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Database\DBStructure;
require_once "boot.php";
require_once "include/dba.php";
$a = new App(dirname(__DIR__));
@include ".htconfig.php";
require_once "include/dba.php";
dba::connect($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
if ($_SERVER["argc"] == 2) {
switch ($_SERVER["argv"][1]) {
case "dryrun":
update_structure(true, false);
DBStructure::update(true, false);
return;
case "update":
update_structure(true, true);
DBStructure::update(true, true);
$build = Config::get('system','build');
if (!x($build)) {
@ -45,10 +46,10 @@ if ($_SERVER["argc"] == 2) {
Config::set('system','build',DB_UPDATE_VERSION);
return;
case "dumpsql":
print_structure(db_definition());
DBStructure::printStructure();
return;
case "toinnodb":
convert_to_innodb();
DBStructure::convertToInnoDB();
return;
}
}

1691
src/Database/DBStructure.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -33,14 +33,14 @@ use Friendica\Object\Image;
* The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
*
* If you change the database schema, the following are required:
* 1. Update the file include/dbstructure.php to match the new schema.
* 1. Update the file src/Database/DBStructure.php to match the new schema.
* 2. If there is a need for a post procession, update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
* This function should perform some post procession steps but no database updates.
* 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
* 4. TEST the upgrade prior to checkin and filing a pull request.
*
* IMPORTANT!
* NEVER do a database change anymore in the update functions! Only do this in the file include/dbstructure.php!
* NEVER do a database change anymore in the update functions! Only do this in the file src/Database/DBStructure.php!
*/
@ -1609,7 +1609,7 @@ ATTENTION!
All following update functions are ONLY for jobs that need to run AFTER the database changes are applied.
Database changes are ONLY applied in the file include/dbstructure.php.
Database changes are ONLY applied in the file src/Database/DBStructure.php.
*/
function update_1177() {