mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-27 20:21:59 +02:00
revert(install): redirect to install in homepage if no database was set
This commit is contained in:
parent
0bab4c7af9
commit
73f094daf2
@ -13,27 +13,27 @@ namespace App\Controllers;
|
|||||||
use App\Models\PodcastModel;
|
use App\Models\PodcastModel;
|
||||||
use CodeIgniter\HTTP\RedirectResponse;
|
use CodeIgniter\HTTP\RedirectResponse;
|
||||||
use Config\Services;
|
use Config\Services;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class HomeController extends BaseController
|
class HomeController extends BaseController
|
||||||
{
|
{
|
||||||
public function index(): RedirectResponse | string
|
public function index(): RedirectResponse | string
|
||||||
{
|
{
|
||||||
$sortOptions = ['activity', 'created_desc', 'created_asc'];
|
$db = db_connect();
|
||||||
$sortBy = in_array($this->request->getGet('sort'), $sortOptions, true) ? $this->request->getGet(
|
if ($db->getDatabase() === '' || ! $db->tableExists('podcasts')) {
|
||||||
'sort'
|
// Database has not been set or could not find the podcasts table
|
||||||
) : 'activity';
|
|
||||||
|
|
||||||
try {
|
|
||||||
$allPodcasts = (new PodcastModel())->getAllPodcasts($sortBy);
|
|
||||||
} catch (Exception) {
|
|
||||||
// Database connection has not been set or could not find the podcasts table
|
|
||||||
// Redirecting to install page because it is likely that Castopod has not been installed yet.
|
// Redirecting to install page because it is likely that Castopod has not been installed yet.
|
||||||
// NB: as base_url wouldn't have been defined here, redirect to install wizard manually
|
// NB: as base_url wouldn't have been defined here, redirect to install wizard manually
|
||||||
$route = Services::routes()->reverseRoute('install');
|
$route = Services::routes()->reverseRoute('install');
|
||||||
return redirect()->to(rtrim(host_url(), '/') . $route);
|
return redirect()->to(rtrim(host_url(), '/') . $route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sortOptions = ['activity', 'created_desc', 'created_asc'];
|
||||||
|
$sortBy = in_array($this->request->getGet('sort'), $sortOptions, true) ? $this->request->getGet(
|
||||||
|
'sort'
|
||||||
|
) : 'activity';
|
||||||
|
|
||||||
|
$allPodcasts = (new PodcastModel())->getAllPodcasts($sortBy);
|
||||||
|
|
||||||
// check if there's only one podcast to redirect user to it
|
// check if there's only one podcast to redirect user to it
|
||||||
if (count($allPodcasts) === 1) {
|
if (count($allPodcasts) === 1) {
|
||||||
return redirect()->route('podcast-activity', [$allPodcasts[0]->handle]);
|
return redirect()->route('podcast-activity', [$allPodcasts[0]->handle]);
|
||||||
|
Loading…
Reference in New Issue
Block a user