PluginProbe
SQLite Database Integration / 3.0.2
SQLite Database Integration v3.0.2
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
sqlite-database-integration / wp-includes / sqlite / install-functions.php

install-functions.php in SQLite Database Integration 3.0.2, at wp-includes/sqlite/install-functions.php

184 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main integration file.
4 */
5
6 /**
7 * Function to create tables according to the schemas of WordPress.
8 *
9 * This is executed only once while installation.
10 *
11 * @return boolean
12 *
13 * @throws PDOException If the database connection fails.
14 */
15 function sqlite_make_db_sqlite() {
16 global $wpdb;
17
18 include_once ABSPATH . 'wp-admin/includes/schema.php';
19
20 $table_schemas = wp_get_db_schema();
21 $queries = explode( ';', $table_schemas );
22 try {
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
36 } catch ( PDOException $err ) {
37 $err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
38 $message = 'Database connection error!<br />';
39 $message .= sprintf( 'Error message is: %s', $err_data[2] ?? $err->getMessage() );
40 wp_die( $message, 'Database Error!' );
41 }
42
43 $query = null;
44
45 try {
46 $translator->beginTransaction();
47 foreach ( $queries as $query ) {
48 $query = trim( $query );
49 if ( empty( $query ) ) {
50 continue;
51 }
52
53 $translator->query( $query );
54 }
55 $translator->commit();
56 } catch ( PDOException $err ) {
57 $translator->rollBack();
58 $message = sprintf(
59 'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
60 var_export( $query, true )
61 );
62 $message .= sprintf( 'Error message is: %s', $err->getMessage() );
63 wp_die( $message, 'Database Error!' );
64 }
65
66 return true;
67 }
68
69 if ( ! function_exists( 'wp_install' ) ) {
70 /**
71 * Installs the site.
72 *
73 * Runs the required functions to set up and populate the database,
74 * including primary admin user and initial options.
75 *
76 * @param string $blog_title Site title.
77 * @param string $user_name User's username.
78 * @param string $user_email User's email.
79 * @param bool $is_public Whether the site is public.
80 * @param string $deprecated Optional. Not used.
81 * @param string $user_password Optional. User's chosen password. Default empty (random password).
82 * @param string $language Optional. Language chosen. Default empty.
83 * @return array {
84 * Data for the newly installed site.
85 *
86 * @type string $url The URL of the site.
87 * @type int $user_id The ID of the site owner.
88 * @type string $password The password of the site owner, if their user account didn't already exist.
89 * @type string $password_message The explanatory message regarding the password.
90 * }
91 */
92 function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
93 if ( ! empty( $deprecated ) ) {
94 _deprecated_argument( __FUNCTION__, '2.6.0' );
95 }
96
97 wp_check_mysql_version();
98 wp_cache_flush();
99 /* SQLite changes: Replace the call to make_db_current_silent() with sqlite_make_db_sqlite(). */
100 sqlite_make_db_sqlite(); // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.sqliteRemoved
101 populate_options();
102 populate_roles();
103
104 update_option( 'blogname', $blog_title );
105 update_option( 'admin_email', $user_email );
106 update_option( 'blog_public', $is_public );
107
108 // Freshness of site - in the future, this could get more specific about actions taken, perhaps.
109 update_option( 'fresh_site', 1 );
110
111 if ( $language ) {
112 update_option( 'WPLANG', $language );
113 }
114
115 $guessurl = wp_guess_url();
116
117 update_option( 'siteurl', $guessurl );
118
119 // If not a public site, don't ping.
120 if ( ! $is_public ) {
121 update_option( 'default_pingback_flag', 0 );
122 }
123
124 /*
125 * Create default user. If the user already exists, the user tables are
126 * being shared among sites. Just set the role in that case.
127 */
128 $user_id = username_exists( $user_name );
129 $user_password = trim( $user_password );
130 $email_password = false;
131 $user_created = false;
132
133 if ( ! $user_id && empty( $user_password ) ) {
134 $user_password = wp_generate_password( 12, false );
135 $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.', 'sqlite-database-integration' );
136 $user_id = wp_create_user( $user_name, $user_password, $user_email );
137 update_user_meta( $user_id, 'default_password_nag', true );
138 $email_password = true;
139 $user_created = true;
140 } elseif ( ! $user_id ) {
141 // Password has been provided.
142 $message = '<em>' . __( 'Your chosen password.', 'sqlite-database-integration' ) . '</em>';
143 $user_id = wp_create_user( $user_name, $user_password, $user_email );
144 $user_created = true;
145 } else {
146 $message = __( 'User already exists. Password inherited.', 'sqlite-database-integration' );
147 }
148
149 $user = new WP_User( $user_id );
150 $user->set_role( 'administrator' );
151
152 if ( $user_created ) {
153 $user->user_url = $guessurl;
154 wp_update_user( $user );
155 }
156
157 wp_install_defaults( $user_id );
158
159 wp_install_maybe_enable_pretty_permalinks();
160
161 flush_rewrite_rules();
162
163 wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.', 'sqlite-database-integration' ) ) );
164
165 wp_cache_flush();
166
167 /**
168 * Fires after a site is fully installed.
169 *
170 * @since 3.9.0
171 *
172 * @param WP_User $user The site owner.
173 */
174 do_action( 'wp_install', $user );
175
176 return array(
177 'url' => $guessurl,
178 'user_id' => $user_id,
179 'password' => $user_password,
180 'password_message' => $message,
181 );
182 }
183 }
184