PluginProbe
SQLite Database Integration / trunk
SQLite Database Integration vtrunk
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
← All changes | wp-includes/sqlite/install-functions.php +21 -68 2.1.15trunk View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 /**
3 3 * Main integration file.
4 - *
5 - * @package wp-sqlite-integration
6 - * @since 1.0.0
7 4 */
8 5
9 6 /**
10 7 * Function to create tables according to the schemas of WordPress.
@@ -10,33 +7,44 @@
10 7 * Function to create tables according to the schemas of WordPress.
11 8 *
12 9 * This is executed only once while installation.
13 10 *
14 - * @since 1.0.0
15 - *
16 11 * @return boolean
17 12 *
18 13 * @throws PDOException If the database connection fails.
19 14 */
20 15 function sqlite_make_db_sqlite() {
16 + global $wpdb;
17 +
21 18 include_once ABSPATH . 'wp-admin/includes/schema.php';
22 19
23 20 $table_schemas = wp_get_db_schema();
24 21 $queries = explode( ';', $table_schemas );
25 22 try {
26 - $pdo = new PDO( 'sqlite:' . FQDB, null, null, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses
23 + $translator = new WP_MySQL_On_SQLite(
24 + sprintf(
25 + 'mysql-on-sqlite:path=%s;dbname=%s',
26 + str_replace( ';', ';;', FQDB ),
27 + str_replace( ';', ';;', $wpdb->dbname )
28 + ),
29 + null,
30 + null,
31 + array(
32 + 'sqlite_journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
33 + )
34 + );
35 + $translator->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
27 36 } catch ( PDOException $err ) {
28 37 $err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
29 38 $message = 'Database connection error!<br />';
30 - $message .= sprintf( 'Error message is: %s', $err_data[2] );
39 + $message .= sprintf( 'Error message is: %s', $err_data[2] ?? $err->getMessage() );
31 40 wp_die( $message, 'Database Error!' );
32 41 }
33 42
34 - $translator = new WP_SQLite_Translator( $pdo );
35 - $query = null;
43 + $query = null;
36 44
37 45 try {
38 - $translator->begin_transaction();
46 + $translator->beginTransaction();
39 47 foreach ( $queries as $query ) {
40 48 $query = trim( $query );
41 49 if ( empty( $query ) ) {
42 50 continue;
@@ -41,74 +49,21 @@
41 49 if ( empty( $query ) ) {
42 50 continue;
43 51 }
44 52
45 - $result = $translator->query( $query );
46 - if ( false === $result ) {
47 - throw new PDOException( $translator->get_error_message() );
48 - }
53 + $translator->query( $query );
49 54 }
50 55 $translator->commit();
51 56 } catch ( PDOException $err ) {
52 - $err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
53 - $err_code = $err_data[1];
54 - $translator->rollback();
57 + $translator->rollBack();
55 58 $message = sprintf(
56 59 'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
57 60 var_export( $query, true )
58 61 );
59 - $message .= sprintf( 'Error message is: %s', $err_data[2] );
62 + $message .= sprintf( 'Error message is: %s', $err->getMessage() );
60 63 wp_die( $message, 'Database Error!' );
61 64 }
62 65
63 - /*
64 - * Debug: Cross-check with MySQL.
65 - * This is for debugging purpose only and requires files
66 - * that are present in the GitHub repository
67 - * but not the plugin published on WordPress.org.
68 - */
69 - if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK ) {
70 - $host = DB_HOST;
71 - $port = 3306;
72 - if ( str_contains( $host, ':' ) ) {
73 - $host_parts = explode( ':', $host );
74 - $host = $host_parts[0];
75 - $port = $host_parts[1];
76 - }
77 - $dsn = 'mysql:host=' . $host . '; port=' . $port . '; dbname=' . DB_NAME;
78 - $pdo_mysql = new PDO( $dsn, DB_USER, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
79 - $pdo_mysql->query( 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' );
80 - $pdo_mysql->query( 'SET time_zone = "+00:00";' );
81 - foreach ( $queries as $query ) {
82 - $query = trim( $query );
83 - if ( empty( $query ) ) {
84 - continue;
85 - }
86 - try {
87 - $pdo_mysql->beginTransaction();
88 - $pdo_mysql->query( $query );
89 - } catch ( PDOException $err ) {
90 - $err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
91 - $err_code = $err_data[1];
92 - // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
93 - if ( 5 == $err_code || 6 == $err_code ) {
94 - // If the database is locked, commit again.
95 - $pdo_mysql->commit();
96 - } else {
97 - $pdo_mysql->rollBack();
98 - $message = sprintf(
99 - 'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
100 - var_export( $query, true )
101 - );
102 - $message .= sprintf( 'Error message is: %s', $err_data[2] );
103 - wp_die( $message, 'Database Error!' );
104 - }
105 - }
106 - }
107 - }
108 -
109 - $pdo = null;
110 -
111 66 return true;
112 67 }
113 68
114 69 if ( ! function_exists( 'wp_install' ) ) {
@@ -116,10 +71,8 @@
116 71 * Installs the site.
117 72 *
118 73 * Runs the required functions to set up and populate the database,
119 74 * including primary admin user and initial options.
120 - *
121 - * @since 1.0.0
122 75 *
123 76 * @param string $blog_title Site title.
124 77 * @param string $user_name User's username.
125 78 * @param string $user_email User's email.