PluginProbe
Redirection / 2.7
Redirection v2.7
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
← All changes | redirection-cli.php +9 -89 4.22.7 View file →
@@ -56,24 +56,21 @@
56 56 return;
57 57 }
58 58
59 59 if ( $format === 'csv' ) {
60 - $file = fopen( $args[0], 'r' );
60 + $file = fopen( $args[ 0 ], 'r' );
61 61
62 62 if ( $file ) {
63 - $count = $importer->load( $group, $args[0], '' );
64 - WP_CLI::success( 'Imported ' . $count . ' as ' . $format );
63 + $count = $importer->load( $group, $file, '' );
64 + WP_CLI::success( 'Imported ' . $count . ' as '.$format );
65 65 } else {
66 66 WP_CLI::error( 'Invalid import file' );
67 67 }
68 68 } else {
69 - $data = @file_get_contents( $args[0] );
70 -
69 + $data = @file_get_contents( $args[ 0 ] );
71 70 if ( $data ) {
72 - $count = $importer->load( $group, $args[0], $data );
73 - WP_CLI::success( 'Imported ' . $count . ' redirects as ' . $format );
74 - } else {
75 - WP_CLI::error( 'Invalid import file' );
71 + $count = $importer->load( $group, $args[ 0 ], $data );
72 + WP_CLI::success( 'Imported ' . $count . ' as '.$format );
76 73 }
77 74 }
78 75 }
79 76
@@ -103,11 +100,11 @@
103 100 WP_CLI::error( 'Invalid export format - json, csv, htaccess, or nginx supported' );
104 101 return;
105 102 }
106 103
107 - $file = fopen( $args[1] === '-' ? 'php://stdout' : $args[1], 'w' );
104 + $file = fopen( $args[ 1 ] === '-' ? 'php://stdout' : $args[ 1 ], 'w' );
108 105 if ( $file ) {
109 - $export = Red_FileIO::export( $args[0], $format );
106 + $export = Red_FileIO::export( $args[ 0 ], $format );
110 107
111 108 if ( $export === false ) {
112 109 WP_CLI::error( 'Invalid module - must be wordpress, apache, nginx, or all' );
113 110 return;
@@ -115,92 +112,15 @@
115 112
116 113 fwrite( $file, $export['data'] );
117 114 fclose( $file );
118 115
119 - WP_CLI::success( 'Exported ' . $export['total'] . ' to ' . $format );
116 + WP_CLI::success( 'Exported ' . $export['total'] .' to '.$format );
120 117 } else {
121 118 WP_CLI::error( 'Invalid output file' );
122 119 }
123 120 }
124 -
125 - /**
126 - * Perform Redirection database actions
127 - *
128 - * ## OPTIONS
129 - *
130 - * <action>
131 - * : The database action to perform: install, remove, upgrade
132 - *
133 - * ## EXAMPLES
134 - *
135 - * wp redirection database install
136 - */
137 - public function database( $args, $extra ) {
138 - $action = false;
139 -
140 - if ( count( $args ) === 0 || ! in_array( $args[0], array( 'install', 'remove', 'upgrade' ), true ) ) {
141 - WP_CLI::error( 'Invalid database action - please use install, remove, or upgrade' );
142 - return;
143 - }
144 -
145 - if ( $args[0] === 'install' ) {
146 - Red_Database::apply_to_sites( function() {
147 - $latest = Red_Database::get_latest_database();
148 - $latest->install();
149 -
150 - WP_CLI::success( 'Site ' . get_current_blog_id() . ' database is installed' );
151 - } );
152 -
153 - WP_CLI::success( 'Database install finished' );
154 - } elseif ( $args[0] === 'upgrade' ) {
155 - Red_Database::apply_to_sites( function() {
156 - $database = new Red_Database();
157 - $status = new Red_Database_Status();
158 -
159 - if ( ! $status->needs_updating() ) {
160 - WP_CLI::success( 'Site ' . get_current_blog_id() . ' database is already the latest version' );
161 - return;
162 - }
163 -
164 - $loop = 0;
165 -
166 - while ( $loop < 50 ) {
167 - $result = $database->apply_upgrade( $status );
168 - $info = $status->get_json();
169 -
170 - if ( ! $info['inProgress'] ) {
171 - break;
172 - }
173 -
174 - if ( $info['status'] === 'error' ) {
175 - WP_CLI::error( 'Site ' . get_current_blog_id() . ' database failed to upgrade: ' . $info['reason'] );
176 - return;
177 - }
178 -
179 - WP_CLI::success( 'Site ' . get_current_blog_id() . ' database upgraded' );
180 -
181 - $loop++;
182 - }
183 - } );
184 -
185 - WP_CLI::success( 'Database upgrade finished' );
186 - } elseif ( $args[0] === 'remove' ) {
187 - Red_Database::apply_to_sites( function() {
188 - $latest = Red_Database::get_latest_database();
189 - $latest->remove();
190 - } );
191 -
192 - WP_CLI::success( 'Database removed' );
193 - }
194 - }
195 121 }
196 122
197 123 if ( defined( 'WP_CLI' ) && WP_CLI ) {
198 124 WP_CLI::add_command( 'redirection import', array( 'Redirection_Cli', 'import' ) );
199 125 WP_CLI::add_command( 'redirection export', array( 'Redirection_Cli', 'export' ) );
200 - WP_CLI::add_command( 'redirection database', array( 'Redirection_Cli', 'database' ) );
201 -
202 - add_action( Red_Flusher::DELETE_HOOK, function() {
203 - $flusher = new Red_Flusher();
204 - $flusher->flush();
205 - } );
206 126 }