Unverified Commit 76a4bf34 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(types): update fake seeders types + fix bugs

parent c72f4be6
......@@ -107,9 +107,9 @@ class ContributorController extends BaseController
{
try {
(new PodcastModel())->addPodcastContributor(
$this->request->getPost('user'),
(int) $this->request->getPost('user'),
$this->podcast->id,
$this->request->getPost('role'),
(int) $this->request->getPost('role'),
);
} catch (Exception) {
return redirect()
......@@ -157,7 +157,7 @@ class ContributorController extends BaseController
(new PodcastModel())->updatePodcastContributor(
$this->user->id,
$this->podcast->id,
$this->request->getPost('role'),
(int) $this->request->getPost('role'),
);
return redirect()->route('contributor-list', [$this->podcast->id]);
......
......@@ -661,8 +661,8 @@ class EpisodeController extends BaseController
$data = [
'podcast_id' => $this->podcast->id,
'episode_id' => $this->episode->id,
'start_time' => (int) $soundbite['start_time'],
'duration' => (int) $soundbite['duration'],
'start_time' => (float) $soundbite['start_time'],
'duration' => (float) $soundbite['duration'],
'label' => $soundbite['label'],
'updated_by' => user_id(),
];
......@@ -688,9 +688,9 @@ class EpisodeController extends BaseController
return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]);
}
public function soundbiteDelete(int $soundbiteId): RedirectResponse
public function soundbiteDelete(string $soundbiteId): RedirectResponse
{
(new SoundbiteModel())->deleteSoundbite($this->podcast->id, $this->episode->id, $soundbiteId);
(new SoundbiteModel())->deleteSoundbite($this->podcast->id, $this->episode->id, (int) $soundbiteId);
return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]);
}
......
......@@ -88,9 +88,9 @@ class EpisodePersonController extends BaseController
return redirect()->back();
}
public function remove(int $personId): RedirectResponse
public function remove(string $personId): RedirectResponse
{
(new PersonModel())->removePersonFromEpisode($this->podcast->id, $this->episode->id, $personId);
(new PersonModel())->removePersonFromEpisode($this->podcast->id, $this->episode->id, (int) $personId);
return redirect()->back();
}
......
......@@ -182,6 +182,15 @@ class PodcastController extends BaseController
->with('errors', $this->validator->getErrors());
}
if (
($partnerId = $this->request->getPost('partner_id')) === '' ||
($partnerLinkUrl = $this->request->getPost('partner_link_url')) === '' ||
($partnerImageUrl = $this->request->getPost('partner_image_url')) === '') {
$partnerId = null;
$partnerLinkUrl = null;
$partnerImageUrl = null;
}
$podcast = new Podcast([
'title' => $this->request->getPost('title'),
'name' => $this->request->getPost('name'),
......@@ -199,11 +208,13 @@ class PodcastController extends BaseController
'type' => $this->request->getPost('type'),
'copyright' => $this->request->getPost('copyright'),
'location' => new Location($this->request->getPost('location_name'),),
'payment_pointer' => $this->request->getPost('payment_pointer'),
'payment_pointer' => $this->request->getPost(
'payment_pointer'
) === '' ? null : $this->request->getPost('payment_pointer'),
'custom_rss_string' => $this->request->getPost('custom_rss'),
'partner_id' => $this->request->getPost('partner_id'),
'partner_link_url' => $this->request->getPost('partner_link_url'),
'partner_image_url' => $this->request->getPost('partner_image_url'),
'partner_id' => $partnerId,
'partner_link_url' => $partnerLinkUrl,
'partner_image_url' => $partnerImageUrl,
'is_blocked' => $this->request->getPost('block') === 'yes',
'is_completed' => $this->request->getPost('complete') === 'yes',
'is_locked' => $this->request->getPost('lock') === 'yes',
......@@ -227,7 +238,7 @@ class PodcastController extends BaseController
$authorize = Services::authorization();
$podcastAdminGroup = $authorize->group('podcast_admin');
$podcastModel->addPodcastContributor(user_id(), $newPodcastId, $podcastAdminGroup->id);
$podcastModel->addPodcastContributor(user_id(), $newPodcastId, (int) $podcastAdminGroup->id);
// set Podcast categories
(new CategoryModel())->setPodcastCategories(
......@@ -277,6 +288,15 @@ class PodcastController extends BaseController
->with('errors', $this->validator->getErrors());
}
if (
($partnerId = $this->request->getPost('partner_id')) === '' ||
($partnerLinkUrl = $this->request->getPost('partner_link_url')) === '' ||
($partnerImageUrl = $this->request->getPost('partner_image_url')) === '') {
$partnerId = null;
$partnerLinkUrl = null;
$partnerImageUrl = null;
}
$this->podcast->title = $this->request->getPost('title');
$this->podcast->description_markdown = $this->request->getPost('description');
......@@ -296,11 +316,13 @@ class PodcastController extends BaseController
$this->podcast->type = $this->request->getPost('type');
$this->podcast->copyright = $this->request->getPost('copyright');
$this->podcast->location = new Location($this->request->getPost('location_name'));
$this->podcast->payment_pointer = $this->request->getPost('payment_pointer');
$this->podcast->payment_pointer = $this->request->getPost(
'payment_pointer'
) === '' ? null : $this->request->getPost('payment_pointer');
$this->podcast->custom_rss_string = $this->request->getPost('custom_rss');
$this->podcast->partner_id = $this->request->getPost('partner_id');
$this->podcast->partner_link_url = $this->request->getPost('partner_link_url');
$this->podcast->partner_image_url = $this->request->getPost('partner_image_url');
$this->podcast->partner_id = $partnerId;
$this->podcast->partner_link_url = $partnerLinkUrl;
$this->podcast->partner_image_url = $partnerImageUrl;
$this->podcast->is_blocked = $this->request->getPost('block') === 'yes';
$this->podcast->is_completed =
$this->request->getPost('complete') === 'yes';
......
......@@ -197,7 +197,7 @@ class PodcastImportController extends BaseController
$authorize = Services::authorization();
$podcastAdminGroup = $authorize->group('podcast_admin');
$podcastModel->addPodcastContributor(user_id(), $newPodcastId, $podcastAdminGroup->id);
$podcastModel->addPodcastContributor(user_id(), $newPodcastId, (int) $podcastAdminGroup->id);
$podcastsPlatformsData = [];
$platformTypes = [
......@@ -218,7 +218,7 @@ class PodcastImportController extends BaseController
foreach ($platformTypes as $platformType) {
foreach ($platformType['elements'] as $platform) {
$platformLabel = $platform->attributes()['platform'];
$platformSlug = slugify($platformLabel);
$platformSlug = slugify((string) $platformLabel);
if ($platformModel->getPlatform($platformSlug) !== null) {
$podcastsPlatformsData[] = [
'platform_slug' => $platformSlug,
......@@ -246,7 +246,7 @@ class PodcastImportController extends BaseController
'full_name' => $fullName,
'unique_name' => slugify($fullName),
'information_url' => $podcastPerson->attributes()['href'],
'image' => new Image(download_file($podcastPerson->attributes()['img'])),
'image' => new Image(download_file((string) $podcastPerson->attributes()['img'])),
'created_by' => user_id(),
'updated_by' => user_id(),
]);
......@@ -301,7 +301,7 @@ class PodcastImportController extends BaseController
$slug = slugify(
$this->request->getPost('slug_field') === 'title'
? $item->title
? (string) $item->title
: basename($item->link),
);
if (in_array($slug, $slugs, true)) {
......@@ -342,7 +342,7 @@ class PodcastImportController extends BaseController
'guid' => $item->guid ?? null,
'title' => $item->title,
'slug' => $slug,
'audio_file' => download_file($item->enclosure->attributes()['url'],),
'audio_file' => download_file((string) $item->enclosure->attributes()['url'],),
'description_markdown' => $converter->convert($itemDescriptionHtml,),
'description_html' => $itemDescriptionHtml,
'image' => $episodeImage,
......@@ -372,7 +372,7 @@ class PodcastImportController extends BaseController
'location' => $location,
'created_by' => user_id(),
'updated_by' => user_id(),
'published_at' => strtotime($item->pubDate),
'published_at' => strtotime((string) $item->pubDate),
]);
$episodeModel = new EpisodeModel();
......@@ -396,7 +396,7 @@ class PodcastImportController extends BaseController
'full_name' => $fullName,
'unique_name' => slugify($fullName),
'information_url' => $episodePerson->attributes()['href'],
'image' => new Image(download_file($episodePerson->attributes()['img'])),
'image' => new Image(download_file((string) $episodePerson->attributes()['img'])),
'created_by' => user_id(),
'updated_by' => user_id(),
]);
......
......@@ -74,9 +74,9 @@ class PodcastPersonController extends BaseController
return redirect()->back();
}
public function remove(int $personId): RedirectResponse
public function remove(string $personId): RedirectResponse
{
(new PersonModel())->removePersonFromPodcast($this->podcast->id, $personId);
(new PersonModel())->removePersonFromPodcast($this->podcast->id, (int) $personId);
return redirect()->back();
}
......
......@@ -90,9 +90,6 @@ class PodcastPlatformController extends BaseController
$podcastPlatform,
) && $podcastPlatform['on_embeddable_player'] === 'yes',
];
return redirect()
->back()
->with('message', lang('Platforms.messages.updateSuccess'));
}
$platformModel->savePodcastPlatforms($this->podcast->id, $platformType, $podcastsPlatformsData);
......
......@@ -143,7 +143,7 @@ class UserController extends BaseController
$authorize = Services::authorization();
$roles = $this->request->getPost('roles');
$authorize->setUserGroups($this->user->id, $roles);
$authorize->setUserGroups($this->user->id, $roles ?? []);
// Success!
return redirect()
......
......@@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\PageNotFoundException;
class PageController extends BaseController
{
protected Page $page;
protected ?Page $page = null;
public function _remap(string $method, string ...$params): mixed
{
......
......@@ -23,8 +23,6 @@ class FakePodcastsAnalyticsSeeder extends Seeder
{
public function run(): void
{
$podcast = (new PodcastModel())->first();
$jsonUserAgents = json_decode(
file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json',),
true,
......@@ -41,13 +39,15 @@ class FakePodcastsAnalyticsSeeder extends Seeder
JSON_THROW_ON_ERROR,
);
if ($podcast) {
$podcast = (new PodcastModel())->first();
if ($podcast !== null) {
$firstEpisode = (new EpisodeModel())
->selectMin('published_at')
->first();
for (
$date = strtotime($firstEpisode->published_at);
$date = strtotime((string) $firstEpisode->published_at);
$date < strtotime('now');
$date = strtotime(date('Y-m-d', $date) . ' +1 day')
) {
......@@ -63,15 +63,15 @@ class FakePodcastsAnalyticsSeeder extends Seeder
->where('`published_at` <= NOW()', null, false)
->findAll();
foreach ($episodes as $episode) {
$age = floor(($date - strtotime($episode->published_at)) / 86400);
$probability1 = (int) floor(exp(3 - $age / 40)) + 1;
$age = floor(($date - strtotime((string) $episode->published_at)) / 86400,);
$probability1 = floor(exp(3 - $age / 40)) + 1;
for (
$lineNumber = 0;
$lineNumber < rand(1, $probability1);
$lineNumber < rand(1, (int) $probability1);
++$lineNumber
) {
$probability2 = (int) floor(exp(6 - $age / 20)) + 10;
$probability2 = floor(exp(6 - $age / 20)) + 10;
$player =
$jsonUserAgents[
......@@ -97,7 +97,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder
'.' .
rand(0, 255);
$cityReader = new Reader(WRITEPATH . 'uploads/GeoLite2-City/GeoLite2-City.mmdb');
$cityReader = new Reader(WRITEPATH . 'uploads/GeoLite2-City/GeoLite2-City.mmdb',);
$countryCode = 'N/A';
$regionCode = 'N/A';
......@@ -113,13 +113,13 @@ class FakePodcastsAnalyticsSeeder extends Seeder
$regionCode = $city->subdivisions === []
? 'N/A'
: $city->subdivisions[0]->isoCode;
$latitude = round($city->location->latitude, 3);
$longitude = round($city->location->longitude, 3);
$latitude = round((float) $city->location->latitude, 3);
$longitude = round((float) $city->location->longitude, 3);
} catch (AddressNotFoundException) {
//Bad luck, bad IP, nothing to do.
}
$hits = rand(0, $probability2);
$hits = rand(0, (int) $probability2);
$analyticsPodcasts[] = [
'podcast_id' => $podcast->id,
......
......@@ -189,7 +189,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder
->first();
for (
$date = strtotime($firstEpisode->published_at);
$date = strtotime((string) $firstEpisode->published_at);
$date < strtotime('now');
$date = strtotime(date('Y-m-d', $date) . ' +1 day')
) {
......@@ -202,7 +202,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder
->where('`published_at` <= NOW()', null, false)
->findAll();
foreach ($episodes as $episode) {
$age = floor(($date - strtotime($episode->published_at)) / 86400);
$age = floor(($date - strtotime((string) $episode->published_at)) / 86400);
$probability1 = (int) floor(exp(3 - $age / 40)) + 1;
for (
......
......@@ -52,10 +52,10 @@ class BlockController extends Controller
return redirect()->back();
}
public function attemptBlockDomain(): RedirectResponse
public function attemptUnblockActor(): RedirectResponse
{
$rules = [
'domain' => 'required',
'actor_id' => 'required',
];
if (! $this->validate($rules)) {
......@@ -65,16 +65,16 @@ class BlockController extends Controller
->with('errors', $this->validator->getErrors());
}
model('BlockedDomainModel')
->blockDomain($this->request->getPost('domain'));
model('ActorModel')
->unblockActor((int) $this->request->getPost('actor_id'));
return redirect()->back();
}
public function attemptUnblockActor(): RedirectResponse
public function attemptBlockDomain(): RedirectResponse
{
$rules = [
'actor_id' => 'required',
'domain' => 'required',
];
if (! $this->validate($rules)) {
......@@ -84,8 +84,8 @@ class BlockController extends Controller
->with('errors', $this->validator->getErrors());
}
model('ActorModel')
->unblockActor($this->request->getPost('actor_id'));
model('BlockedDomainModel')
->blockDomain($this->request->getPost('domain'));
return redirect()->back();
}
......
......@@ -102,7 +102,7 @@ class BlockedDomainModel extends Model
// set all actors from the domain as blocked
model('ActorModel')
->where('domain', $name)
->set('is_blocked', 1)
->set('is_blocked', '1')
->update();
$result = $this->insert([
......@@ -133,7 +133,7 @@ class BlockedDomainModel extends Model
// unblock all actors from the domain
model('ActorModel')
->where('domain', $name)
->set('is_blocked', 0)
->set('is_blocked', '0')
->update();
$result = $this->delete($name);
......
......@@ -28,7 +28,7 @@ class PageModel extends Model
/**
* @var string[]
*/
protected $allowedFields = ['id', 'title', 'slug', 'content'];
protected $allowedFields = ['id', 'title', 'slug', 'content_markdown', 'content_html'];
/**
* @var string
......@@ -52,7 +52,7 @@ class PageModel extends Model
'title' => 'required',
'slug' =>
'required|regex_match[/^[a-zA-Z0-9\-]{1,191}$/]|is_unique[pages.slug,id,{id}]',
'content' => 'required',
'content_markdown' => 'required',
];
/**
......
......@@ -45,7 +45,7 @@
'class' => 'form-textarea',
'required' => 'required',
],
old('content', $page->content, false),
old('content', $page->content_markdown, false),
'data-editor="markdown"',
) ?>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment