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\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Database\DBStructure;
require_once 'include/network.php'; require_once 'include/network.php';
require_once 'include/plugin.php'; require_once 'include/plugin.php';
@ -37,13 +38,20 @@ require_once 'include/pgettext.php';
require_once 'include/nav.php'; require_once 'include/nav.php';
require_once 'include/identity.php'; require_once 'include/identity.php';
require_once 'update.php'; require_once 'update.php';
require_once 'include/dbstructure.php';
define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Asparagus'); define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev'); define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23'); define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1236); 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. * @brief Constant with a HTML line break.
@ -694,9 +702,9 @@ function update_db(App $a)
// run new update routine // run new update routine
// it update the structure in one call // it update the structure in one call
$retval = update_structure(false, true); $retval = DBStructure::update(false, true);
if ($retval) { if ($retval) {
update_fail( DBStructure::updateFail(
DB_UPDATE_VERSION, DB_UPDATE_VERSION,
$retval $retval
); );
@ -742,7 +750,7 @@ function run_update_function($x)
if ($retval) { if ($retval) {
//send the administrator an e-mail //send the administrator an e-mail
update_fail( DBStructure::updateFail(
$x, $x,
sprintf(t('Update %s failed. See error logs.'), $x) sprintf(t('Update %s failed. See error logs.'), $x)
); );

View File

@ -1,6 +1,7 @@
<?php <?php
use \Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
require_once('include/datetime.php'); require_once('include/datetime.php');
@ -829,12 +830,12 @@ class dba {
/** /**
* @brief Build the array with the table relations * @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. * This process must only be started once, since the value is cached.
*/ */
private static function build_relation_data() { private static function build_relation_data() {
$definition = db_definition(); $definition = DBStructure::definition();
foreach ($definition AS $table => $structure) { foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) { 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\Config;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\User; use Friendica\Model\User;
@ -708,7 +709,7 @@ function admin_page_summary(App $a)
$warningtext = array(); $warningtext = array();
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$showwarning = true; $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 // 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 // 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) { if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) {
require_once("include/dbstructure.php"); DBStructure::update(false, true);
update_structure(false, true);
} }
if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) { if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
$showwarning = true; $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); $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'))) { if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
require_once("include/dbstructure.php"); $retval = DBStructure::update(false, true);
$retval = update_structure(false, true);
if (!$retval) { if (!$retval) {
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />"; $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />";
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');

View File

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

View File

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