use App\Models\FluidbookAuditLink;
use App\Models\FluidbookPublication;
use App\Models\FluidbookCollection;
+use App\Models\ShortLink;
use Fluidbook\Tools\Links\Link as LinkAlias;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
}
//Log::info('Deleted ' . count($missing) . ' links');
//Log::info('Job exécuté avec succès');
+
+ ShortLink::touchChangeFile();
}
}
return $res->longurl ?? false;
}
- public static function shorturl($url, $shortener)
+ public static function shorturl($url, $shortener, $force = true)
{
- return cache()->remember('shorturl_' . $shortener . '_' . $url, 3600, function () use ($url, $shortener) {
+ $cacheKey = 'shorturl_' . $shortener . '_' . $url;
+ if ($force) {
+ cache()->delete($cacheKey);
+ }
+ return cache()->remember($cacheKey, 3600, function () use ($url, $shortener) {
$res = self::_request('shorturl', ['url' => $url], $shortener, $code);
if ($code === 200) {
use Cubist\Backpack\Magic\Traits\CustomDataSource;
use Cubist\Util\Files\Files;
use DateTime;
+use Illuminate\Support\Facades\Log;
class ShortLink extends ToolboxModel
{
$data = [];
foreach (LinkShortener::getAvaiableShorteners(true) as $id => $s) {
- try {
- foreach (LinkShortener::listAll($id)->result as $i) {
- $shorturl = 'https://' . $s['domain'] . '/' . $i->keyword;
- $time = new DateTime($i->timestamp);
- $d = [
- 'id' => hash('sha256', $id . '/' . $i->keyword),
- 'shortlink' => $shorturl,
- 'url' => $i->url,
- 'server' => $id,
- 'created_at' => $time,
- 'updated_at' => $time,
- 'deleted_at' => null,
- 'created_ok' => '1',
- 'owner' => $s['owner'],
- ];
- if (isset($auditLinks[$i->url])) {
- $d = array_merge($d, $auditLinks[$i->url]);
- } else {
- continue;
- }
- $data[$d['id']] = $d;
- }
- } catch (\Exception $e) {
+ foreach (LinkShortener::listAll($id)->result as $i) {
+ $shorturl = 'https://' . $s['domain'] . '/' . $i->keyword;
+ $time = new DateTime($i->timestamp);
+ $d = [
+ 'id' => hash('sha256', $id . '/' . $i->keyword),
+ 'shortlink' => $shorturl,
+ 'url' => $i->url,
+ 'server' => $id,
+ 'created_at' => $time,
+ 'updated_at' => $time,
+ 'deleted_at' => null,
+ 'created_ok' => '1',
+ 'owner' => $s['owner'],
+ ];
+ if (isset($auditLinks[$i->url])) {
+ $d = array_merge($d, $auditLinks[$i->url]);
+ } else {
+ continue;
+ }
+ $d['fluidbook_links']=json_encode($d['fluidbook_links']);
+ $data[$d['id']] = $d;
}
}
return $data;
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)) {