self::_fixLinks($links);
}
- public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [])
+ public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [], $triggerJobs = true)
{
/** @var FluidbookPublication $fluidbook */
$fluidbook = FluidbookPublication::withoutGlobalScopes()->find($book_id);
file_put_contents($base . '.links3.gz', gzencode(json_encode($lr)));
copy($base . '.links3.gz', $latestLinks);
copy($base . '.meta3.gz', $latestMeta);
-
+
$fluidbook->touch();
- if ($fluidbook->linkShortener && $fluidbook->linkShortener != "none") {
- AuditLinkRegister::dispatch();
+
+ if ($triggerJobs) {
+ if ($fluidbook->linkShortener && $fluidbook->linkShortener != "none") {
+ AuditLinkRegister::dispatch();
+ }
}
}
namespace App\Models;
use App\Fields\ShortLinkFluidbooks;
+use App\Fluidbook\Link\Link;
+use App\Fluidbook\Link\LinksData;
+use App\Jobs\AuditLinkRegister;
use App\Models\Base\ToolboxModel;
use Carbon\Carbon;
use Cubist\Backpack\CubistBackpackServiceProvider;
use Cubist\Backpack\Magic\Fields\URL;
use Cubist\Backpack\Magic\Traits\CustomDataSource;
use Cubist\Util\Files\Files;
+use Cubist\Util\WebVideo;
use DateTime;
class ShortLink extends ToolboxModel
return Files::mkdir(resource_path('shortlink')) . 'lastchange';
}
- public static function shouldRefreshDatabase()
- {
- return true;
- }
-
public function onSaved(): bool
{
- if ($this->url !== LinkShortener::expand($this->shortlink, $this->server)) {
+ $formerValue = LinkShortener::expand($this->shortlink, $this->server);
+ if ($this->url !== $formerValue) {
LinkShortener::updateURL($this->shortlink, $this->url, $this->server);
+ $fbl = json_decode($this->fluidbook_links, true);
+ if (count($fbl) > 0) {
+ $fluidbooks = [];
+ foreach ($fbl as $l) {
+ if (!isset($fluidbooks[$l['fluidbook_id']])) {
+ $fluidbooks[$l['fluidbook_id']] = [];
+ }
+ $fluidbooks[$l['fluidbook_id']][$l['link_id']] = $l;
+ }
+
+ foreach ($fluidbooks as $id => $changedLinks) {
+ LinksData::getLinksAndRulers($id, $links, $rulers);
+ foreach ($changedLinks as $uid => $l) {
+ $currentLink = $links[$uid];
+ if ($currentLink['type'] == Link::WEBVIDEO && $currentLink['video_service'] == 'youtube') {
+ $links[$uid]['to'] = WebVideo::_findVideoId($this->url, 'youtube');
+ } else {
+ $links[$uid]['to'] = $this->uid;
+ }
+ }
+ LinksData::saveLinksInFile($id, backpack_user()->id, __('Lien court :shortlink édité', ['shortlink' => $this->shortlink]), $links, $rulers, [], [], false);
+ }
+ }
+ AuditLinkRegister::dispatchSync();
+ static::touchChangeFile();
}
return parent::onSaved();
}