<?php
$sql_query = 'INSERT INTO ' . $config['table_prefix'] . 'cron ';
$sql_query .= <<<'EOT'
(`description`, `period`, `thread_name`, `last_start_time`, `last_stop_time`, `command`) VALUES ('_remove_null_from_db_v3_', '*/30 19-23 * * *', 'db_update', now(), now(), '$result = sql_query(\"SELECT * FROM information_schema.columns WHERE \n    table_schema = \'\" . $config[\'dbname\'] . \"\' AND table_name LIKE \'\" . $config[\'table_prefix\'] . \"%\' AND column_name != \'id\' AND data_type != \'enum\' AND (column_default IS NULL OR column_default = \'NULL\')\");\nwhile ($field = sql_fetch_assoc($result)) {\n    if ($field[\'DATA_TYPE\'] == \'decimal\' || $field[\'DATA_TYPE\'] == \'float\' || strpos($field[\'DATA_TYPE\'], \'int\') !== false) {\n        $field[\'COLUMN_DEFAULT\'] = \"0\";\n    } elseif ($field[\'DATA_TYPE\'] == \'datetime\') {\n        $field[\'COLUMN_DEFAULT\'] = \"\'0000-00-00 00:00:00\'\";\n    } else {\n        $field[\'COLUMN_DEFAULT\'] = \"\'\'\";\n    }\n    sql_query(\"ALTER TABLE \" . $field[\'TABLE_NAME\'] . \" MODIFY `\" . $field[\'COLUMN_NAME\'] . \"` \" . $field[\'COLUMN_TYPE\'] . \" NOT NULL DEFAULT \" . $field[\'COLUMN_DEFAULT\']);\n}\nsql_query(\"DELETE FROM \" . $config[\'table_prefix\'] . \"cron WHERE description = \'_remove_null_from_db_v3_\'\");\nsql_query(\"DELETE FROM \" . $config[\'table_prefix\'] . \"cron_queue WHERE thread_name = \'db_update\'\");');
EOT;
run_query($sql_query);