File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -169,8 +169,24 @@ protected function sqlite_reset( $assoc_args ) {
169169 }
170170 }
171171
172- // Recreate.
173- $ this ->sqlite_create ( $ assoc_args );
172+ // Create directory if needed.
173+ $ db_dir = dirname ( $ db_path );
174+ if ( ! is_dir ( $ db_dir ) ) {
175+ if ( ! mkdir ( $ db_dir , 0755 , true ) ) {
176+ WP_CLI ::error ( "Could not create directory: {$ db_dir }" );
177+ }
178+ }
179+
180+ // Recreate the SQLite database file.
181+ try {
182+ $ pdo = new PDO ( 'sqlite: ' . $ db_path );
183+ $ pdo ->setAttribute ( PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
184+ // Execute a simple query to initialize the database.
185+ $ pdo ->exec ( 'CREATE TABLE IF NOT EXISTS _wpcli_test (id INTEGER) ' );
186+ $ pdo ->exec ( 'DROP TABLE _wpcli_test ' );
187+ } catch ( PDOException $ e ) {
188+ WP_CLI ::error ( 'Could not create SQLite database: ' . $ e ->getMessage () );
189+ }
174190
175191 WP_CLI ::success ( 'Database reset. ' );
176192 }
You can’t perform that action at this time.
0 commit comments