]> git.mxchange.org Git - friendica.git/blobdiff - include/dbstructure.php
Degrade priority step by step
[friendica.git] / include / dbstructure.php
index 1daf042d538d143e7b5925f1dbcfeaba3c88db1d..32fd304f4ba8658177260db1a7fb9cb9c580a219 100644 (file)
@@ -3,8 +3,8 @@
 use Friendica\App;
 use Friendica\Core\Config;
 
-require_once("boot.php");
-require_once("include/text.php");
+require_once "boot.php";
+require_once "include/text.php";
 
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
@@ -30,7 +30,7 @@ function convert_to_innodb() {
                $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
                echo $sql."\n";
 
-               $result = @$db->q($sql);
+               $result = $db->q($sql);
                if (!dbm::is_result($result)) {
                        print_update_error($db, $sql);
                }
@@ -85,6 +85,7 @@ function update_fail($update_id, $error_message) {
 
 
        /*
+        @TODO deprecated code?
        $email_tpl = get_intltext_template("update_fail_eml.tpl");
        $email_msg = replace_macros($email_tpl, array(
                '$sitename' => $a->config['sitename'],
@@ -133,7 +134,7 @@ function table_structure($table) {
                        // On utf8mb4 a varchar index can only have a length of 191
                        // The "show index" command sometimes returns this value although this value wasn't added manually.
                        // Because we don't want to add this number to every index, we ignore bigger numbers
-                       if (($index["Sub_part"] != "") AND (($index["Sub_part"] < 191) OR ($index["Key_name"] == "PRIMARY"))) {
+                       if (($index["Sub_part"] != "") && (($index["Sub_part"] < 191) || ($index["Key_name"] == "PRIMARY"))) {
                                $column .= "(".$index["Sub_part"].")";
                        }
 
@@ -232,7 +233,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
        }
 
        // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
-       if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
+       if ((version_compare($db->server_info(), '5.7.4') >= 0) &&
                !(strpos($db->server_info(), 'MariaDB') !== false)) {
                $ignore = '';
        } else {
@@ -381,7 +382,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                $field_definition = $database[$name]["fields"][$fieldname];
 
                                // Define the default collation if not given
-                               if (!isset($parameters['Collation']) AND !is_null($field_definition['Collation'])) {
+                               if (!isset($parameters['Collation']) && !is_null($field_definition['Collation'])) {
                                        $parameters['Collation'] = 'utf8mb4_general_ci';
                                } else {
                                        $parameters['Collation'] = null;
@@ -389,7 +390,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
 
                                if ($field_definition['Collation'] != $parameters['Collation']) {
                                        $sql2 = db_modify_table_field($fieldname, $parameters);
-                                       if (($sql3 == "") OR (substr($sql3, -2, 2) == "; ")) {
+                                       if (($sql3 == "") || (substr($sql3, -2, 2) == "; ")) {
                                                $sql3 .= "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
                                        } else {
                                                $sql3 .= ", ".$sql2;
@@ -513,7 +514,7 @@ function db_field_command($parameters, $create = true) {
        if ($parameters["extra"] != "")
                $fieldstruct .= " ".$parameters["extra"];
 
-       /*if (($parameters["primary"] != "") AND $create)
+       /*if (($parameters["primary"] != "") && $create)
                $fieldstruct .= " PRIMARY KEY";*/
 
        return($fieldstruct);
@@ -530,7 +531,7 @@ function db_create_table($name, $fields, $verbose, $action, $indexes=null) {
        $primary_keys = array();
        foreach ($fields AS $fieldname => $field) {
                $sql_rows[] = "`".dbesc($fieldname)."` ".db_field_command($field);
-               if (x($field,'primary') and $field['primary']!='') {
+               if (x($field,'primary') && $field['primary']!='') {
                        $primary_keys[] = $fieldname;
                }
        }
@@ -1205,7 +1206,7 @@ function db_definition() {
                                        "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
                                        "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
                                        "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
-                                       "created" => array("type" => "datetime", "default" => NULL_DATE),
+                                       "pid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
@@ -1739,11 +1740,14 @@ function db_definition() {
                                        "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
                                        "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "executed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
+                                       "done" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
                                        "pid" => array("pid"),
+                                       "parameter" => array("parameter(64)"),
                                        "priority_created" => array("priority", "created"),
+                                       "executed" => array("executed"),
                                        )
                        );
 
@@ -1762,13 +1766,13 @@ function dbstructure_run(&$argv, &$argc) {
        }
 
        if (is_null($db)) {
-               @include(".htconfig.php");
-               require_once("include/dba.php");
+               @include ".htconfig.php";
+               require_once "include/dba.php";
                $db = new dba($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 ($argc==2) {
+       if ($argc == 2) {
                switch ($argv[1]) {
                        case "dryrun":
                                update_structure(true, false);
@@ -1778,7 +1782,7 @@ function dbstructure_run(&$argv, &$argc) {
 
                                $build = get_config('system','build');
                                if (!x($build)) {
-                                       set_config('system','build',DB_UPDATE_VERSION);
+                                       set_config('system', 'build', DB_UPDATE_VERSION);
                                        $build = DB_UPDATE_VERSION;
                                }
 
@@ -1788,7 +1792,9 @@ function dbstructure_run(&$argv, &$argc) {
                                // run any left update_nnnn functions in update.php
                                for ($x = $stored; $x < $current; $x ++) {
                                        $r = run_update_function($x);
-                                       if (!$r) break;
+                                       if (!$r) {
+                                               break;
+                                       }
                                }
 
                                set_config('system','build',DB_UPDATE_VERSION);
@@ -1815,7 +1821,7 @@ function dbstructure_run(&$argv, &$argc) {
 
 }
 
-if (array_search(__file__,get_included_files())===0) {
+if (array_search(__FILE__,get_included_files())===0) {
        dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
        killme();
 }