-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1188 from shikorism/develop
Release 2024.6.1
- Loading branch information
Showing
16 changed files
with
472 additions
and
213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
|
||
class CleanLock extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'tissue:lock:clean'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete obsolete global lock file'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$lockDir = storage_path('global_lock'); | ||
if (!is_dir($lockDir)) { | ||
return Command::SUCCESS; | ||
} | ||
$dh = opendir($lockDir); | ||
if (!$dh) { | ||
$this->error("Can't open directory: {$lockDir}"); | ||
|
||
return Command::FAILURE; | ||
} | ||
try { | ||
while (($file = readdir($dh)) !== false) { | ||
$path = $lockDir . DIRECTORY_SEPARATOR . $file; | ||
if (!is_file($path) || str_starts_with($file, '.')) { | ||
continue; | ||
} | ||
|
||
// あまり古くないファイルはスキップ | ||
$mtime = filemtime($path); | ||
if ($mtime === false || !Carbon::createFromTimestamp($mtime)->isBefore(Carbon::now()->subDays(7))) { | ||
continue; | ||
} | ||
|
||
// サーバープロセスで使用中だと困るので排他ロックを取ってから削除する | ||
$fp = fopen($path, 'r'); | ||
if ($fp === false) { | ||
$this->error("Error (can't open lock file): {$file}"); | ||
continue; | ||
} | ||
try { | ||
if (!flock($fp, LOCK_EX)) { | ||
$this->error("Error (can't lock file): {$file}"); | ||
continue; | ||
} | ||
|
||
if (unlink($path)) { | ||
$this->info("Delete: {$file}"); | ||
} else { | ||
$this->error("Error (can't delete lock file): {$file}"); | ||
} | ||
} finally { | ||
if (!fclose($fp)) { | ||
$this->error("Error (can't close lock file): {$file}"); | ||
} | ||
} | ||
} | ||
} finally { | ||
closedir($dh); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions; | ||
|
||
use App\Utilities\GlobalLock; | ||
|
||
/** | ||
* {@see GlobalLock} のロック処理に失敗した時にスローされる例外 | ||
*/ | ||
class GlobalLockException extends \RuntimeException | ||
{ | ||
} |
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,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\MetadataResolver; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class FxTwitterResolver implements TwitterResolver | ||
{ | ||
public function __construct(private Client $client, private OGPResolver $ogpResolver) | ||
{ | ||
} | ||
|
||
public function resolve(string $url): Metadata | ||
{ | ||
$url = preg_replace('/(www\.)?((mobile|m)\.)?(twitter|x)\.com/u', 'fxtwitter.com', $url); | ||
|
||
$res = $this->client->get($url); | ||
$html = (string) $res->getBody(); | ||
|
||
return $this->ogpResolver->parse($html); | ||
} | ||
} |
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
Oops, something went wrong.