mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-13 11:37:46 +02:00
fix: check for database connection and podcasts table existence before redirecting to install
fix signature regex
This commit is contained in:
parent
cacd228098
commit
eb74e81c3d
6 changed files with 22 additions and 29 deletions
|
|
@ -11,25 +11,25 @@ declare(strict_types=1);
|
|||
namespace App\Controllers;
|
||||
|
||||
use App\Models\PodcastModel;
|
||||
use CodeIgniter\Database\Exceptions\DatabaseException;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use Config\Services;
|
||||
use mysqli_sql_exception;
|
||||
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
public function index(): RedirectResponse | string
|
||||
{
|
||||
try {
|
||||
$allPodcasts = (new PodcastModel())->findAll();
|
||||
} catch (mysqli_sql_exception | DatabaseException) {
|
||||
// An error was caught when retrieving the podcasts from the database.
|
||||
$connections = \CodeIgniter\Database\Config::getConnections();
|
||||
$db = db_connect();
|
||||
if ($connections === [] || ! $db->tableExists('podcasts')) {
|
||||
// Cannot connect to the database or cannot find the podcasts table
|
||||
// Redirecting to install page because it is likely that Castopod Host has not been installed yet.
|
||||
// NB: as base_url wouldn't have been defined here, redirect to install wizard manually
|
||||
$route = Services::routes()->reverseRoute('install');
|
||||
return redirect()->to(rtrim(host_url(), '/') . $route);
|
||||
}
|
||||
|
||||
$allPodcasts = (new PodcastModel())->findAll();
|
||||
|
||||
// check if there's only one podcast to redirect user to it
|
||||
if (count($allPodcasts) === 1) {
|
||||
return redirect()->route('podcast-activity', [$allPodcasts[0]->name]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue