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

This commit is contained in:
Yassine Doghri 2021-06-08 16:57:04 +00:00
parent c72f4be6d8
commit 76a4bf3441
No known key found for this signature in database
GPG Key ID: 3E7F89498B960C9F
15 changed files with 89 additions and 70 deletions

View File

@ -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]);

View File

@ -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]);
}

View File

@ -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();
}

View File

@ -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';

View File

@ -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(),
]);

View File

@ -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();
}

View File

@ -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);

View File

@ -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()

View File

@ -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
{

View File

@ -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,

View File

@ -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 (

View File

@ -52,6 +52,25 @@ class BlockController extends Controller
return redirect()->back();
}
public function attemptUnblockActor(): RedirectResponse
{
$rules = [
'actor_id' => 'required',
];
if (! $this->validate($rules)) {
return redirect()
->back()
->withInput()
->with('errors', $this->validator->getErrors());
}
model('ActorModel')
->unblockActor((int) $this->request->getPost('actor_id'));
return redirect()->back();
}
public function attemptBlockDomain(): RedirectResponse
{
$rules = [
@ -71,25 +90,6 @@ class BlockController extends Controller
return redirect()->back();
}
public function attemptUnblockActor(): RedirectResponse
{
$rules = [
'actor_id' => 'required',
];
if (! $this->validate($rules)) {
return redirect()
->back()
->withInput()
->with('errors', $this->validator->getErrors());
}
model('ActorModel')
->unblockActor($this->request->getPost('actor_id'));
return redirect()->back();
}
public function attemptUnblockDomain(): RedirectResponse
{
$rules = [

View File

@ -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);

View File

@ -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',
];
/**

View File

@ -45,7 +45,7 @@
'class' => 'form-textarea',
'required' => 'required',
],
old('content', $page->content, false),
old('content', $page->content_markdown, false),
'data-editor="markdown"',
) ?>
</div>