Unverified Commit 92536ddb authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(activity-pub): get database records using new model instances

update types and some remap logic
parent 4a28127b
......@@ -34,7 +34,7 @@ class PermissionModel extends MythAuthPermissionModel
$groupPermissions = $this->db
->table('auth_groups_permissions')
->select('id, auth_permissions.name')
->join('auth_permissions', 'auth_permissions.id = permission_id', 'inner',)
->join('auth_permissions', 'auth_permissions.id = permission_id', 'inner')
->where('group_id', $groupId)
->get()
->getResultObject();
......
......@@ -123,7 +123,7 @@ Events::on('on_undo_follow', function ($actor, $targetActor): void {
* @param Note $note
*/
Events::on('on_note_add', function ($note): void {
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
$note = $note->reply_to_note;
}
......@@ -147,7 +147,7 @@ Events::on('on_note_add', function ($note): void {
* @param Note $note
*/
Events::on('on_note_remove', function ($note): void {
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
Events::trigger('on_note_remove', $note->reply_to_note);
}
......@@ -207,7 +207,7 @@ Events::on('on_note_reblog', function ($actor, $note): void {
cache()
->deleteMatching("page_note#{$note->id}*");
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}");
}
});
......@@ -239,7 +239,7 @@ Events::on('on_note_undo_reblog', function ($reblogNote): void {
cache()
->deleteMatching("page_note#{$reblogNote->id}*");
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}");
}
......@@ -308,7 +308,7 @@ Events::on('on_note_favourite', function ($actor, $note): void {
cache()
->deleteMatching("page_note#{$note->id}*");
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}*");
}
......@@ -340,7 +340,7 @@ Events::on('on_note_undo_favourite', function ($actor, $note): void {
cache()
->deleteMatching("page_note#{$note->id}*");
if ($note->is_reply) {
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}*");
}
......
......@@ -27,19 +27,24 @@ class ContributorController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
$this->podcast = (new PodcastModel())->getPodcastById((int) $params[0]);
if (count($params) === 0) {
throw PageNotFoundException::forPageNotFound();
}
if (count($params) <= 1) {
return $this->{$method}();
if (($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) === null) {
throw PageNotFoundException::forPageNotFound();
}
$this->podcast = $podcast;
if (
($this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0],)) !== null
count($params) > 1 &&
($this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0])) === null
) {
return $this->{$method}();
throw PageNotFoundException::forPageNotFound();
}
throw PageNotFoundException::forPageNotFound();
return $this->{$method}();
}
public function list(): string
......@@ -57,7 +62,7 @@ class ContributorController extends BaseController
public function view(): string
{
$data = [
'contributor' => (new UserModel())->getPodcastContributor($this->user->id, $this->podcast->id,),
'contributor' => (new UserModel())->getPodcastContributor($this->user->id, $this->podcast->id),
];
replace_breadcrumb_params([
......@@ -173,7 +178,7 @@ class ContributorController extends BaseController
$podcastModel = new PodcastModel();
if (
! $podcastModel->removePodcastContributor($this->user->id, $this->podcast->id,)
! $podcastModel->removePodcastContributor($this->user->id, $this->podcast->id)
) {
return redirect()
->back()
......
......@@ -33,11 +33,13 @@ class EpisodeController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) === null
($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) === null
) {
throw PageNotFoundException::forPageNotFound();
}
$this->podcast = $podcast;
if (count($params) > 1) {
if (
! ($this->episode = (new EpisodeModel())
......@@ -135,7 +137,7 @@ class EpisodeController extends BaseController
'audio_file' => $this->request->getFile('audio_file'),
'description_markdown' => $this->request->getPost('description'),
'image' => $image,
'location' => new Location($this->request->getPost('location_name'),),
'location' => new Location($this->request->getPost('location_name')),
'transcript' => $this->request->getFile('transcript'),
'chapters' => $this->request->getFile('chapters'),
'parental_advisory' =>
......@@ -276,7 +278,7 @@ class EpisodeController extends BaseController
}
} elseif ($transcriptChoice === 'remote-url') {
if (
($transcriptFileRemoteUrl = $this->request->getPost('transcript_file_remote_url',)) &&
($transcriptFileRemoteUrl = $this->request->getPost('transcript_file_remote_url')) &&
(($transcriptFile = $this->episode->transcript_file) &&
$transcriptFile !== null)
) {
......@@ -295,7 +297,7 @@ class EpisodeController extends BaseController
}
} elseif ($chaptersChoice === 'remote-url') {
if (
($chaptersFileRemoteUrl = $this->request->getPost('chapters_file_remote_url',)) &&
($chaptersFileRemoteUrl = $this->request->getPost('chapters_file_remote_url')) &&
(($chaptersFile = $this->episode->chapters_file) &&
$chaptersFile !== null)
) {
......
......@@ -31,7 +31,7 @@ class EpisodePersonController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) &&
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) &&
($this->episode = (new EpisodeModel())
->where([
'id' => $params[1],
......
......@@ -27,7 +27,7 @@ class PersonController extends BaseController
}
if (
($this->person = (new PersonModel())->getPersonById((int) $params[0],)) !== null
($this->person = (new PersonModel())->getPersonById((int) $params[0])) !== null
) {
return $this->{$method}();
}
......
......@@ -33,7 +33,7 @@ class PodcastController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
) {
return $this->{$method}();
}
......@@ -45,7 +45,7 @@ class PodcastController extends BaseController
{
if (! has_permission('podcasts-list')) {
$data = [
'podcasts' => (new PodcastModel())->getUserPodcasts((int) user_id(),),
'podcasts' => (new PodcastModel())->getUserPodcasts((int) user_id()),
];
} else {
$data = [
......@@ -162,7 +162,7 @@ class PodcastController extends BaseController
$data = [
'languageOptions' => $languageOptions,
'categoryOptions' => $categoryOptions,
'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE'),),
'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE')),
];
return view('admin/podcast/create', $data);
......@@ -207,7 +207,7 @@ class PodcastController extends BaseController
'publisher' => $this->request->getPost('publisher'),
'type' => $this->request->getPost('type'),
'copyright' => $this->request->getPost('copyright'),
'location' => new Location($this->request->getPost('location_name'),),
'location' => new Location($this->request->getPost('location_name')),
'payment_pointer' => $this->request->getPost(
'payment_pointer'
) === '' ? null : $this->request->getPost('payment_pointer'),
......
......@@ -56,7 +56,7 @@ class PodcastImportController extends BaseController
$data = [
'languageOptions' => $languageOptions,
'categoryOptions' => $categoryOptions,
'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE'),),
'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE')),
];
return view('admin/podcast/import', $data);
......@@ -132,10 +132,10 @@ class PodcastImportController extends BaseController
$podcast = new Podcast([
'name' => $this->request->getPost('name'),
'imported_feed_url' => $this->request->getPost('imported_feed_url',),
'new_feed_url' => base_url(route_to('podcast_feed', $this->request->getPost('name')),),
'imported_feed_url' => $this->request->getPost('imported_feed_url'),
'new_feed_url' => base_url(route_to('podcast_feed', $this->request->getPost('name'))),
'title' => (string) $feed->channel[0]->title,
'description_markdown' => $converter->convert($channelDescriptionHtml,),
'description_markdown' => $converter->convert($channelDescriptionHtml),
'description_html' => $channelDescriptionHtml,
'image' => new Image($imageFile),
'language_code' => $this->request->getPost('language'),
......@@ -323,7 +323,7 @@ class PodcastImportController extends BaseController
property_exists($nsItunes, 'image') && $nsItunes->image !== null &&
$nsItunes->image->attributes()['href'] !== null
) {
$episodeImage = new Image(download_file((string) $nsItunes->image->attributes()['href'],));
$episodeImage = new Image(download_file((string) $nsItunes->image->attributes()['href']));
} else {
$episodeImage = null;
}
......@@ -342,8 +342,8 @@ class PodcastImportController extends BaseController
'guid' => $item->guid ?? null,
'title' => $item->title,
'slug' => $slug,
'audio_file' => download_file((string) $item->enclosure->attributes()['url'],),
'description_markdown' => $converter->convert($itemDescriptionHtml,),
'audio_file' => download_file((string) $item->enclosure->attributes()['url']),
'description_markdown' => $converter->convert($itemDescriptionHtml),
'description_html' => $itemDescriptionHtml,
'image' => $episodeImage,
'parental_advisory' =>
......
......@@ -27,7 +27,7 @@ class PodcastPersonController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
) {
unset($params[0]);
return $this->{$method}(...$params);
......@@ -42,7 +42,7 @@ class PodcastPersonController extends BaseController
$data = [
'podcast' => $this->podcast,
'podcastPersons' => (new PersonModel())->getPodcastPersons($this->podcast->id,),
'podcastPersons' => (new PersonModel())->getPodcastPersons($this->podcast->id),
'personOptions' => (new PersonModel())->getPersonOptions(),
'taxonomyOptions' => (new PersonModel())->getTaxonomyOptions(),
];
......
......@@ -28,7 +28,7 @@ class PodcastPlatformController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
) {
unset($params[0]);
return $this->{$method}(...$params);
......@@ -49,7 +49,7 @@ class PodcastPlatformController extends BaseController
$data = [
'podcast' => $this->podcast,
'platformType' => $platformType,
'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType,),
'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType),
];
replace_breadcrumb_params([
......
......@@ -35,20 +35,25 @@ class EpisodeController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null
($podcast = (new PodcastModel())->getPodcastByName($params[0])) === null
) {
throw PageNotFoundException::forPageNotFound();
}
$this->podcast = $podcast;
if (
($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1],)) !== null
($episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1])) === null
) {
unset($params[1]);
unset($params[0]);
return $this->{$method}(...$params);
throw PageNotFoundException::forPageNotFound();
}
throw PageNotFoundException::forPageNotFound();
$this->episode = $episode;
unset($params[1]);
unset($params[0]);
return $this->{$method}(...$params);
}
public function index(): string
......
......@@ -155,7 +155,7 @@ class InstallController extends Controller
if (! $this->validate($rules)) {
return redirect()
->to((host_url() === null ? config('App') ->baseURL : host_url()) . config('App')->installGateway,)
->to((host_url() === null ? config('App') ->baseURL : host_url()) . config('App')->installGateway)
->withInput()
->with('errors', $this->validator->getErrors());
}
......@@ -173,7 +173,7 @@ class InstallController extends Controller
helper('text');
// redirect to full install url with new baseUrl input
return redirect()->to(reduce_double_slashes($baseUrl . '/' . config('App')->installGateway,));
return redirect()->to(reduce_double_slashes($baseUrl . '/' . config('App')->installGateway));
}
public function databaseConfig(): string
......@@ -198,10 +198,10 @@ class InstallController extends Controller
}
self::writeEnv([
'database.default.hostname' => $this->request->getPost('db_hostname',),
'database.default.hostname' => $this->request->getPost('db_hostname'),
'database.default.database' => $this->request->getPost('db_name'),
'database.default.username' => $this->request->getPost('db_username',),
'database.default.password' => $this->request->getPost('db_password',),
'database.default.username' => $this->request->getPost('db_username'),
'database.default.password' => $this->request->getPost('db_password'),
'database.default.DBPrefix' => $this->request->getPost('db_prefix'),
]);
......
......@@ -39,8 +39,12 @@ class NoteController extends ActivityPubNoteController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) < 2) {
throw PageNotFoundException::forPageNotFound();
}
if (
($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null
($this->podcast = (new PodcastModel())->getPodcastByName($params[0])) === null
) {
throw PageNotFoundException::forPageNotFound();
}
......@@ -48,11 +52,13 @@ class NoteController extends ActivityPubNoteController
$this->actor = $this->podcast->actor;
if (
count($params) > 1 &&
! ($this->note = (new NoteModel())->getNoteById($params[1]))
($note = (new NoteModel())->getNoteById($params[1])) === null
) {
throw PageNotFoundException::forPageNotFound();
}
$this->note = $note;
unset($params[0]);
unset($params[1]);
......@@ -125,7 +131,7 @@ class NoteController extends ActivityPubNoteController
if (
$episodeUri &&
($params = extract_params_from_episode_uri(new URI($episodeUri))) &&
($episode = (new EpisodeModel())->getEpisodeBySlug($params['podcastName'], $params['episodeSlug'],))
($episode = (new EpisodeModel())->getEpisodeBySlug($params['podcastName'], $params['episodeSlug']))
) {
$newNote->episode_id = $episode->id;
}
......@@ -135,7 +141,7 @@ class NoteController extends ActivityPubNoteController
$noteModel = new NoteModel();
if (
! $noteModel
->addNote($newNote, ! (bool) $newNote->episode_id, true,)
->addNote($newNote, ! (bool) $newNote->episode_id, true)
) {
return redirect()
->back()
......
......@@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\PageNotFoundException;
class PageController extends BaseController
{
protected ?Page $page = null;
protected Page $page;
public function _remap(string $method, string ...$params): mixed
{
......@@ -25,12 +25,14 @@ class PageController extends BaseController
}
if (
$this->page = (new PageModel())->where('slug', $params[0])->first()
($page = (new PageModel())->where('slug', $params[0])->first()) === null
) {
return $this->{$method}();
throw PageNotFoundException::forPageNotFound();
}
throw PageNotFoundException::forPageNotFound();
$this->page = $page;
return $this->{$method}();
}
public function index(): string
......
......@@ -30,13 +30,15 @@ class PodcastController extends BaseController
}
if (
($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) !== null
($podcast = (new PodcastModel())->getPodcastByName($params[0])) === null
) {
unset($params[0]);
return $this->{$method}(...$params);
throw PageNotFoundException::forPageNotFound();
}
throw PageNotFoundException::forPageNotFound();
$this->podcast = $podcast;
unset($params[0]);
return $this->{$method}(...$params);
}
public function activity(): string
......@@ -61,7 +63,7 @@ class PodcastController extends BaseController
if (! ($cachedView = cache($cacheName))) {
$data = [
'podcast' => $this->podcast,
'notes' => (new NoteModel())->getActorPublishedNotes($this->podcast->actor_id,),
'notes' => (new NoteModel())->getActorPublishedNotes($this->podcast->actor_id),
];
// if user is logged in then send to the authenticated activity view
......
......@@ -277,7 +277,7 @@ class AuthSeeder extends Seeder
foreach ($action['has_permission'] as $role) {
// link permission to specified groups
$dataGroupsPermissions[] = [
'group_id' => $this->getGroupIdByName($role, $dataGroups,),
'group_id' => $this->getGroupIdByName($role, $dataGroups),
'permission_id' => $permissionId,
];
}
......
......@@ -24,7 +24,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder
public function run(): void
{
$jsonUserAgents = json_decode(
file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json',),
file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json'),
true,
512,
JSON_THROW_ON_ERROR,
......@@ -63,7 +63,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder
->where('`published_at` <= NOW()', null, false)
->findAll();
foreach ($episodes as $episode) {
$age = floor(($date - strtotime((string) $episode->published_at)) / 86400,);
$age = floor(($date - strtotime((string) $episode->published_at)) / 86400);
$probability1 = floor(exp(3 - $age / 40)) + 1;
for (
......@@ -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';
......
......@@ -396,7 +396,7 @@ class Episode extends Entity
public function getLink(): string
{
return base_url(route_to('episode', $this->getPodcast() ->name, $this->attributes['slug'],));
return base_url(route_to('episode', $this->getPodcast() ->name, $this->attributes['slug']));
}
public function getEmbeddablePlayerUrl(string $theme = null): string
......@@ -410,7 +410,7 @@ class Episode extends Entity
$this->attributes['slug'],
$theme,
)
: route_to('embeddable-player', $this->getPodcast() ->name, $this->attributes['slug'],),
: route_to('embeddable-player', $this->getPodcast() ->name, $this->attributes['slug']),
);
}
......@@ -471,7 +471,7 @@ class Episode extends Entity
{
if ($this->description === null) {
$this->description = trim(
preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html']),),
preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html'])),
);
}
......
......@@ -17,9 +17,6 @@ use RuntimeException;
/**
* @property int|null $episode_id
* @property Episode|null $episode
* @property Actor $actor
* @property Note $reblog_of_note
* @property Note $reply_to_note
*/
class Note extends ActivityPubNote
{
......
......@@ -320,7 +320,7 @@ class Podcast extends Entity
{
if ($this->description === null) {
$this->description = trim(
(string) preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html']),),
(string) preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html'])),
);
}
......
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