Changeset 601


Ignore:
Timestamp:
Apr 27, 2017 4:43:35 PM (7 years ago)
Author:
anonymous
Message:

Updated every instance of 'zero' date 0000-00-00 to use 1000-01-01 if mysql version >= 5.7.4

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/init_codebase_tables.cli.php

    r573 r601  
    146146            // Lock!
    147147            require_once CODEBASE_PATH . '/lib/Lock.inc.php';
     148            require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php';
    148149            $lock =& Lock::getInstance(new Auth_SQL('codebase'));
    149150            $lock->setParam(array('create_table' => true));
     
    162163            // Version!
    163164            require_once CODEBASE_PATH . '/lib/Version.inc.php';
     165            require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php';
    164166            $version = Version::getInstance(new Auth_SQL('codebase'));
    165167            $version->setParam(array('create_table' => true));
  • trunk/bin/module_maker/list_template.cli.php

    r533 r601  
    119119            $listrows[] = "<\x3fphp echo mb_strlen(\$list[\$i]['$field'])<50 \x3f oTxt(\$list[\$i]['$field'], true) : oTxt(trim(mb_substr(\$list[\$i]['$field'], 0, 50)) . '...'); \x3f>";
    120120        } else if (preg_match('/.*(begin|start).*date.*/i', $field)) {
    121             $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
     121            $listrows[] = "<\x3fphp echo \$db->getParam('zero_date') == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
    122122        } else if (preg_match('/.*(end|expire).*date.*/i', $field)) {
    123123            $listrows[] = "<\x3fphp echo '9999-12-31' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
  • trunk/bin/module_maker/skel/public.php

    r468 r601  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    6060        WHERE %PRIMARY_KEY% = '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "'
    6161        AND publish = 'true'
    62         __///__AND (publish_date <= CURDATE() OR publish_date = '0000-00-00')
    63         __///__AND (expire_date > CURDATE() OR expire_date = '0000-00-00')
     62        __///__AND (publish_date <= CURDATE() OR publish_date = '" . $db->escapeString($db->getParam('zero_date')) . "')
     63        __///__AND (expire_date > CURDATE() OR expire_date = '" . $db->escapeString($db->getParam('zero_date')) . "')
    6464    ");
    6565    if (!$item = mysql_fetch_assoc($qid)) {
  • trunk/lib/ACL.inc.php

    r534 r601  
    162162
    163163            // acl_tbl
    164             $db->query("
     164            $db->query(sprintf("
    165165                CREATE TABLE IF NOT EXISTS acl_tbl (
    166166                    aro_id SMALLINT UNSIGNED NOT NULL DEFAULT '0',
     
    168168                    axo_id SMALLINT UNSIGNED NOT NULL DEFAULT '0',
    169169                    access ENUM('allow', 'deny') DEFAULT NULL,
    170                     added_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     170                    added_datetime DATETIME NOT NULL DEFAULT '%s 00:00:00',
    171171                    UNIQUE KEY (aro_id, aco_id, axo_id),
    172172                    KEY (access)
    173173                ) ENGINE=MyISAM
    174             ");
     174            ", $db->getParam('zero_date')));
    175175            if (!$db->columnExists('acl_tbl', array(
    176176                'aro_id',
     
    192192            // aro_tbl, aco_tbl, axo_tbl
    193193            foreach (array('aro', 'aco', 'axo') as $a_o) {
    194                 $db->query("
    195                     CREATE TABLE IF NOT EXISTS {$a_o}_tbl (
    196                         {$a_o}_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    197                         name VARCHAR(" . $this->getParam('name_max_length') . ") NOT NULL DEFAULT '',
     194                $db->query(sprintf("
     195                    CREATE TABLE IF NOT EXISTS %1\$s_tbl (
     196                        %1\$s_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
     197                        name VARCHAR(%2\$s) NOT NULL DEFAULT '',
    198198                        lft MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
    199199                        rgt MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
    200                         added_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     200                        added_datetime DATETIME NOT NULL DEFAULT '%3\$s 00:00:00',
    201201                        UNIQUE KEY name (name(15)),
    202202                        KEY transversal (lft, rgt)
    203203                    ) ENGINE=MyISAM;
    204                 ");
     204                ", $a_o, $this->getParam('name_max_length'), $db->getParam('zero_date')));
    205205
    206206                if (!$db->columnExists("{$a_o}_tbl", array(
  • trunk/lib/Auth_SQL.inc.php

    r593 r601  
    175175
    176176            // The minimal columns for a table compatible with the Auth_SQL class.
    177             $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
    178                 " . $this->getParam('db_primary_key') . " MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    179                 " . $this->getParam('db_username_column') . " varchar(255) NOT NULL default '',
    180                 userpass VARCHAR(255) NOT NULL DEFAULT '',
    181                 userpass_hashtype TINYINT UNSIGNED NOT NULL DEFAULT '0',
    182                 first_name VARCHAR(50) NOT NULL DEFAULT '',
    183                 last_name VARCHAR(50) NOT NULL DEFAULT '',
    184                 email VARCHAR(255) NOT NULL DEFAULT '',
    185                 login_abuse_exempt ENUM('true') DEFAULT NULL,
    186                 blocked ENUM('true') DEFAULT NULL,
    187                 blocked_reason VARCHAR(255) NOT NULL DEFAULT '',
    188                 abuse_warning_level TINYINT NOT NULL DEFAULT '0',
    189                 seconds_online INT NOT NULL DEFAULT '0',
    190                 last_login_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    191                 last_access_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    192                 last_login_ip VARCHAR(45) NOT NULL DEFAULT '0.0.0.0',
    193                 added_by_user_id SMALLINT DEFAULT NULL,
    194                 modified_by_user_id SMALLINT DEFAULT NULL,
    195                 added_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    196                 modified_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    197                 KEY " . $this->getParam('db_username_column') . " (" . $this->getParam('db_username_column') . "),
    198                 KEY userpass (userpass),
    199                 KEY email (email),
    200                 KEY last_login_datetime (last_login_datetime),
    201                 KEY last_access_datetime (last_access_datetime)
    202             )");
     177            $db->query(sprintf(
     178                "CREATE TABLE IF NOT EXISTS %1\$s (
     179                    %2\$s MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
     180                    %3\$s varchar(255) NOT NULL default '',
     181                    userpass VARCHAR(255) NOT NULL DEFAULT '',
     182                    userpass_hashtype TINYINT UNSIGNED NOT NULL DEFAULT '0',
     183                    first_name VARCHAR(50) NOT NULL DEFAULT '',
     184                    last_name VARCHAR(50) NOT NULL DEFAULT '',
     185                    email VARCHAR(255) NOT NULL DEFAULT '',
     186                    login_abuse_exempt ENUM('true') DEFAULT NULL,
     187                    blocked ENUM('true') DEFAULT NULL,
     188                    blocked_reason VARCHAR(255) NOT NULL DEFAULT '',
     189                    abuse_warning_level TINYINT NOT NULL DEFAULT '0',
     190                    seconds_online INT NOT NULL DEFAULT '0',
     191                    last_login_datetime DATETIME NOT NULL DEFAULT '%4\$s 00:00:00',
     192                    last_access_datetime DATETIME NOT NULL DEFAULT '%4\$s 00:00:00',
     193                    last_login_ip VARCHAR(45) NOT NULL DEFAULT '0.0.0.0',
     194                    added_by_user_id SMALLINT DEFAULT NULL,
     195                    modified_by_user_id SMALLINT DEFAULT NULL,
     196                    added_datetime DATETIME NOT NULL DEFAULT '%4\$s 00:00:00',
     197                    modified_datetime DATETIME NOT NULL DEFAULT '%4\$s 00:00:00',
     198                    KEY %5\$s (%5\$s),
     199                    KEY userpass (userpass),
     200                    KEY email (email),
     201                    KEY last_login_datetime (last_login_datetime),
     202                    KEY last_access_datetime (last_access_datetime)
     203                )",
     204                $db->escapeString($this->getParam('db_table')),
     205                $this->getParam('db_primary_key'),
     206                $this->getParam('db_username_column'),
     207                $db->getParam('zero_date'),
     208                $this->getParam('db_username_column')
     209            ));
    203210
    204211            if (!$db->columnExists($this->getParam('db_table'), array(
     
    232239                    $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_login_table')), LOG_INFO, __FILE__, __LINE__);
    233240                }
    234                 $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_login_table') . " (
    235                     " . $this->getParam('db_primary_key') . " MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
    236                     login_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    237                     remote_ip_binary CHAR(32) NOT NULL DEFAULT '',
    238                     KEY " . $this->getParam('db_primary_key') . " (" . $this->getParam('db_primary_key') . "),
    239                     KEY login_datetime (login_datetime),
    240                     KEY remote_ip_binary (remote_ip_binary)
    241                 )");
     241                $db->query(sprintf(
     242                    "CREATE TABLE IF NOT EXISTS %1\$s (
     243                        %2\$s MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
     244                        login_datetime DATETIME NOT NULL DEFAULT '%3\$s 00:00:00',
     245                        remote_ip_binary CHAR(32) NOT NULL DEFAULT '',
     246                        KEY %4\$s (%4\$s),
     247                        KEY login_datetime (login_datetime),
     248                        KEY remote_ip_binary (remote_ip_binary)
     249                    )",
     250                    $this->getParam('db_login_table'),
     251                    $this->getParam('db_primary_key'),
     252                    $db->getParam('zero_date'),
     253                    $this->getParam('db_primary_key')
     254                ));
    242255
    243256                if (!$db->columnExists($this->getParam('db_login_table'), array(
     
    327340
    328341            // FIX ME: Should we check if the session is active?
    329             $db->query("
    330                 UPDATE " . $this->_params['db_table'] . " SET
    331                 seconds_online = seconds_online + ABS(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_access_datetime)),
    332                 last_login_datetime = '0000-00-00 00:00:00'
    333                 WHERE " . $this->_params['db_primary_key'] . " = '" . $this->get('user_id') . "'
    334             ");
     342            $db->query(sprintf(
     343                "UPDATE %s SET
     344                    seconds_online = seconds_online + ABS(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_access_datetime)),
     345                    last_login_datetime = '%s 00:00:00'
     346                    WHERE %s = '%s'
     347                ",
     348                $this->_params['db_table'],
     349                $db->getParam('zero_date'),
     350                $this->_params['db_primary_key'],
     351                $this->get('user_id')
     352            ));
    335353        }
    336354        $_SESSION['_auth_sql'][$this->_ns] = array(
  • trunk/lib/DB.inc.php

    r575 r601  
    6565        // Script stops on db error. TRUE recommended for production sites.
    6666        'db_die_on_failure' => true,
     67
     68        // Special date settings. These will dynamically changes depending on MySQL version or settings.
     69        'zero_date' => '0000-00-00',
     70        'infinity_date' => '9999-12-31',
    6771    );
    6872
     
    7882
    7983    /**
     84     * Constructor.
     85     */
     86    public function __construct()
     87    {
     88        // Initialize default parameters.
     89        $this->_params = array_merge($this->_params, $this->_param_defaults);
     90    }
     91
     92    /**
    8093     * This method enforces the singleton pattern for this class.
    8194     *
     
    181194        } else {
    182195            $app->logMsg(sprintf('%s is not a known character_set.', $app->getParam('character_set')), LOG_ERR, __FILE__, __LINE__);
     196        }
     197
     198        // Update config for this version of MySQL.
     199        if (version_compare(mysql_get_server_info(), '5.7.4', '>=')) {
     200            $this->setParam(array('zero_date' => '1000-01-01'));
    183201        }
    184202
  • trunk/lib/Lock.inc.php

    r592 r601  
    117117                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_INFO, __FILE__, __LINE__);
    118118            }
    119             $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
     119            $db->query(sprintf("CREATE TABLE IF NOT EXISTS %s (
    120120                lock_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    121121                record_table varchar(255) NOT NULL default '',
     
    124124                title varchar(255) NOT NULL default '',
    125125                set_by_admin_id smallint(11) NOT NULL default '0',
    126                 lock_datetime datetime NOT NULL default '0000-00-00 00:00:00',
     126                lock_datetime datetime NOT NULL default '%s 00:00:00',
    127127                KEY record_table (record_table),
    128128                KEY record_key (record_key),
    129129                KEY record_val (record_val)
    130             )");
     130            )", $db->escapeString($this->getParam('db_table')), $db->getParam('zero_date')));
    131131
    132132            if (!$db->columnExists($this->getParam('db_table'), array(
  • trunk/lib/Utilities.inc.php

    r600 r601  
    939939    $db =& DB::getInstance();
    940940
    941     if ($db->isConnected() && version_compare(mysql_get_server_info(), '5.7.4', '>=')) {
     941    if ($db->isConnected() && mb_strpos($db->getParam('zero_date'), '-') !== false) {
    942942        // Mysql version >= 5.7.4 stopped allowing a "zero" date of 0000-00-00.
    943943        // https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date
    944         $zero_y = '1000';
    945         $zero_m = '01';
    946         $zero_d = '01';
     944        $zero_date_parts = explode('-', $db->getParam('zero_date'));
     945        $zero_y = $zero_date_parts[0];
     946        $zero_m = $zero_date_parts[1];
     947        $zero_d = $zero_date_parts[2];
    947948    } else {
    948949        $zero_y = '0000';
  • trunk/lib/Validator.inc.php

    r597 r601  
    429429    {
    430430        $app =& App::getInstance();
    431         if (empty($val) || '0000-00-00 00:00:00' == $val || '0000-00-00' == $val || '00:00:00' == $val) {
     431
     432        if (empty($val) || '0000-00-00 00:00:00' == $val || '1000-01-01 00:00:00' == $val || '0000-00-00' == $val || '1000-01-01' == $val || '00:00:00' == $val) {
    432433            return true;
    433434        }
  • trunk/lib/Version.inc.php

    r550 r601  
    123123                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_INFO, __FILE__, __LINE__);
    124124            }
    125             $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
     125            $db->query(sprintf("CREATE TABLE IF NOT EXISTS %s (
    126126                version_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    127127                record_table VARCHAR(255) NOT NULL DEFAULT '',
     
    133133                version_notes VARCHAR(255) NOT NULL DEFAULT '',
    134134                saved_by_user_id SMALLINT(11) NOT NULL DEFAULT '0',
    135                 version_datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     135                version_datetime DATETIME NOT NULL DEFAULT '%s 00:00:00',
    136136                KEY record_table (record_table),
    137137                KEY record_key (record_key),
    138138                KEY record_val (record_val)
    139             )");
     139            )", $db->escapeString($this->getParam('db_table')), $db->getParam('zero_date')));
    140140
    141141            if (!$db->columnExists($this->getParam('db_table'), array(
  • trunk/services/admins.php

    r535 r601  
    258258        'email' => '',
    259259        'seconds_online' => '0',
    260         'last_login_datetime' => '0000-00-00 00:00:00',
    261         'last_access_datetime' => '0000-00-00 00:00:00',
     260        'last_login_datetime' => '',
     261        'last_access_datetime' => '',
    262262        'last_login_ip' => '0.0.0.0',
    263263        'added_by_user_id' => '',
    264264        'modified_by_user_id' => '',
    265         'added_datetime' => '0000-00-00 00:00:00',
    266         'modified_datetime' => '0000-00-00 00:00:00',
     265        'added_datetime' => '',
     266        'modified_datetime' => '',
    267267        'new_op' => 'insert',
    268268        'submit_buttons' => array(
     
    315315        'email' => '',
    316316        'seconds_online' => '0',
    317         'last_login_datetime' => '0000-00-00 00:00:00',
    318         'last_access_datetime' => '0000-00-00 00:00:00',
     317        'last_login_datetime' => '',
     318        'last_access_datetime' => '',
    319319        'last_login_ip' => '0.0.0.0',
    320320        'added_by_user_id' => '',
    321321        'modified_by_user_id' => '',
    322         'added_datetime' => '0000-00-00 00:00:00',
    323         'modified_datetime' => '0000-00-00 00:00:00',
     322        'added_datetime' => '',
     323        'modified_datetime' => '',
    324324        'new_op' => 'update',
    325325        'old_username' => $frm['username'],
Note: See TracChangeset for help on using the changeset viewer.