diff --git a/app/Console/Commands/MigrateFilesExecute.php b/app/Console/Commands/MigrateFilesExecute.php new file mode 100644 index 0000000..22fe7b6 --- /dev/null +++ b/app/Console/Commands/MigrateFilesExecute.php @@ -0,0 +1,110 @@ +where('filename', $file['filename'] ) + ->where('old_path', $file['old_path'] ) + ->where('wp_post_id', (int) $file['wp_post_id'] ) + ->where('uuid', $file['uuid'] ) + ->where('new_path', $this->getNewPath( $file ) ) + ->exists(); + + if( $exists ) + return; + + $entryId = DB::table('migrations_logs') + ->where('source_system', 'wp') + ->where('source_table', 'wp_posts') + ->where('target_table', 'entries' ) + ->where('source_id', (int) $file['wp_post_id'] ) + ->value('target_id'); + + if( !$entryId ){ + $this->info("Not copied entry for {$file['wp_post_id']}"); + return; + } + + $fileId = DB::table('entry_files')->insertGetId([ + 'entry_id' => $entryId, + 'filename' => $file['filename'], + 'filepath' => $this->getNewPath( $file ), + 'favorite_server' => $this->option('favorite-server') ?? "oedipus", + 'favorite_at' => now(), + 'filesize' => (int) $file['filesize'], + 'created_at' => now(), + 'updated_at' => now(), + 'file_uuid' => $file['uuid'], + 'state' => $this->getState( $file ), + 'online_patcher' => (int) EntryHelpers::enableOnlinePatcherBasedOnExtension( $file['filename'] ), + 'secondary_online_patcher' => 0, + 'download_count' => 0 + ]); + + if( !$fileId ){ + $this->info( "Not created file for {$file['wp_post_id']}" ); + return; + } + + DB::table('migration_files')->insert([ + 'filename' => $file['filename'], + 'old_path' => $file['old_path'], + 'wp_post_id' => (int) $file['wp_post_id'], + 'uuid' => $file['uuid'], + 'new_path' => $this->getNewPath( $file ), + 'created_at' => now(), + 'updated_at' => now(), + ]); + + $this->info( "Created file for {$file['wp_post_id']}" ); + + } + + public function handle() + { + $csvFile = $this->option('csv-file'); + if( !$csvFile || !is_file($csvFile) ){ + $this->error('Missing CSV file Path'); + return self::FAILURE; + } + + $rows = SimpleExcelReader::create($csvFile)->useDelimiter(';')->getRows(); + $rows->each(function(array $row){ + $this->createEntryFile($row); + }); + + return self::SUCCESS; + } +} diff --git a/composer.json b/composer.json index a142f35..9c19bd6 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "livewire/livewire": "^4.3", "predis/predis": "^3.4", "spatie/laravel-activitylog": "^5.0", - "spatie/laravel-sitemap": "*" + "spatie/laravel-sitemap": "*", + "spatie/simple-excel": "^3.10" }, "require-dev": { "barryvdh/laravel-debugbar": "^4.2", diff --git a/composer.lock b/composer.lock index cf9bca2..f9c5256 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6ebcacd70675cd6b17a9428bb0050a51", + "content-hash": "7c9b7fd591cb7e152659cf998900a531", "packages": [ { "name": "artesaos/seotools", @@ -5865,6 +5865,66 @@ ], "time": "2026-04-27T14:27:52+00:00" }, + { + "name": "spatie/simple-excel", + "version": "3.10.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/simple-excel.git", + "reference": "2aa4cd9da6f29a23e4f7b6f4c6944dce204ea47a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/simple-excel/zipball/2aa4cd9da6f29a23e4f7b6f4c6944dce204ea47a", + "reference": "2aa4cd9da6f29a23e4f7b6f4c6944dce204ea47a", + "shasum": "" + }, + "require": { + "illuminate/support": "^9.0|^10.0|^11.0|^12.0|^13.0", + "openspout/openspout": "^4.30", + "php": "^8.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.4|^10.5|^11.0|^12.0", + "spatie/pest-plugin-snapshots": "^1.1|^2.1", + "spatie/phpunit-snapshot-assertions": "^4.0|^5.1", + "spatie/temporary-directory": "^1.2|^2.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\SimpleExcel\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Read and write simple Excel and CSV files", + "homepage": "https://github.com/spatie/simple-excel", + "keywords": [ + "simple-excel", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/simple-excel/tree/3.10.0" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2026-06-15T06:21:16+00:00" + }, { "name": "symfony/clock", "version": "v8.0.8", diff --git a/database/migrations/2026_06_26_145915_create_migration_files_table.php b/database/migrations/2026_06_26_145915_create_migration_files_table.php new file mode 100644 index 0000000..deb5ff8 --- /dev/null +++ b/database/migrations/2026_06_26_145915_create_migration_files_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('filename'); + $table->string('old_path'); + $table->unsignedBigInteger('wp_post_id'); + $table->uuid('uuid'); + $table->string('new_path'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('migration_files'); + } +};