upgrade_versions = [ '3.4.0', '3.8.3', ]; } /** * Create files and directories. * * @since 3.6.0 */ private function create_files() { // install files and folders for exported files and prevent hotlinking $upload_dir = wp_upload_dir(); $download_method = get_option( 'woocommerce_file_download_method', 'force' ); $files = [ [ 'base' => $upload_dir['basedir'] . '/csv_imports', 'file' => 'index.html', 'content' => '' ], ]; if ( 'redirect' !== $download_method ) { $files[] = [ 'base' => $upload_dir['basedir'] . '/csv_imports', 'file' => '.htaccess', 'content' => 'deny from all' ]; } foreach ( $files as $file ) { if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ); if ( $file_handle ) { fwrite( $file_handle, $file['content'] ); fclose( $file_handle ); } } } } /** * Performs installation tasks. * * @since 3.6.0 */ protected function install() { // set up csv imports folder $this->create_files(); } /** * Runs version upgrade tasks. * * @since 3.6.0 * * @param string $installed_version */ protected function upgrade( $installed_version ) { // forces logging enabled so we can record upgrade messages add_filter( 'wc_csv_import_suite_logging_enabled', [ $this, 'enable_logging' ], 999 ); parent::upgrade( $installed_version ); // restores the normal logging behavior remove_filter( 'wc_csv_import_suite_logging_enabled', [ $this, 'enable_logging'], 999 ); } /** * Forces enable logging (callback method). * * @internal * * @since 3.6.0 * * @return true */ public function enable_logging() { return true; } /** * Updates plugin to v3.4.0 * * @since 3.6.0 */ protected function upgrade_to_3_4_0() { // set up csv imports folder $this->create_files(); } /** * Updates plugin to v3.8.3 * * @since 3.8.3 */ protected function upgrade_to_3_8_3() { if ( $handler = $this->get_plugin()->get_background_fix_coupons_usage_count_instance() ) { // create_job() expects an non-empty array of attributes $handler->create_job( [ 'created_at' => current_time( 'mysql' ) ] ); $handler->dispatch(); } } }