-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
16 changed files
with
467 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Enums\ModelAttribute; | ||
use App\Helper\HtmlMeta; | ||
use App\Helper\LinkIconMapper; | ||
use App\Models\Link; | ||
use App\Models\Tag; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Carbon; | ||
|
||
class ImportLinkJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
public int $userId, | ||
public array $link, | ||
public Tag $importTag, | ||
public bool $generateMeta | ||
) { | ||
$this->onQueue('import'); | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
if ($this->generateMeta) { | ||
$linkMeta = (new HtmlMeta)->getFromUrl($this->link['url']); | ||
$title = $this->link['name'] ?: $linkMeta['title']; | ||
$description = $this->link['description'] ?: $linkMeta['description']; | ||
} else { | ||
$title = $this->link['name']; | ||
$description = $this->link['description']; | ||
} | ||
|
||
if (isset($this->link['public'])) { | ||
$visibility = $this->link['public'] ? ModelAttribute::VISIBILITY_PUBLIC : ModelAttribute::VISIBILITY_PRIVATE; | ||
} else { | ||
$visibility = usersettings('links_default_visibility', $this->userId); | ||
} | ||
|
||
$newLink = new Link([ | ||
'user_id' => $this->userId, | ||
'url' => $this->link['url'], | ||
'title' => $title, | ||
'description' => $description, | ||
'icon' => LinkIconMapper::getIconForUrl($this->link['url']), | ||
'visibility' => $visibility, | ||
]); | ||
|
||
$newLink->created_at = $this->link['dateCreated'] | ||
? Carbon::createFromTimestamp($this->link['dateCreated']) | ||
: Carbon::now(); | ||
$newLink->updated_at = Carbon::now(); | ||
$newLink->timestamps = false; | ||
$newLink->save(); | ||
|
||
$newTags = [$this->importTag->id]; | ||
|
||
if (!empty($this->link['tags'])) { | ||
foreach ($this->link['tags'] as $tag) { | ||
$newTag = Tag::firstOrCreate([ | ||
'user_id' => $this->userId, | ||
'name' => $tag, | ||
'visibility' => usersettings('tags_default_visibility', $this->userId), | ||
]); | ||
$newTags[] = $newTag->id; | ||
} | ||
} | ||
|
||
$newLink->tags()->sync($newTags); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
database/migrations/2024_10_06_211654_update_failed_jobs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::table('failed_jobs', function (Blueprint $table) { | ||
$table->string('uuid')->unique()->after('id'); | ||
$table->longText('payload')->change(); | ||
$table->longText('exception')->change(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::table('failed_jobs', function (Blueprint $table) { | ||
$table->dropColumn(['uuid']); | ||
$table->text('payload')->change(); | ||
$table->text('exception')->change(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
<?php | ||
return [ | ||
'import' => 'Import', | ||
'import_queue' => 'Import Queue', | ||
'failed_imports' => 'Failed Imports', | ||
'scheduled_for' => 'Scheduled for', | ||
'start_import' => 'Start Import', | ||
'import_running' => 'Import running...', | ||
'import_file' => 'File for Import', | ||
|
||
'import_help' => 'You can import your existing browser bookmarks here. Usually, bookmarks are exported into an .html file by your browser. Select the file here and start the import.<br>Depending on the number of bookmarks this process may take some time.', | ||
'import_help' => 'You can import your existing browser bookmarks here. Usually, bookmarks are exported into an .html file by your browser. Select the file here and start the import. Please note that a cron must be configured for the import to work.', | ||
|
||
'import_networkerror' => 'Something went wrong while trying to import the bookmarks. Please check your browser console for details or consult the application logs.', | ||
'import_error' => 'Something went wrong while trying to import the bookmarks. Please consult the application logs.', | ||
'import_empty' => 'Could not import any bookmarks. Either the uploaded file is corrupt or empty.', | ||
'import_successfully' => ':imported links imported successfully, :skipped skipped. All imported links have been assigned the tag :taglink.', | ||
'import_successfully' => ':queued links are queued for import and will be processed consecutively. :skipped links were skipped because they already exist in the database. All imported links will be assigned the tag :taglink.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.