XF 2.2 Programmatically Create Media Gallery Report

Andy R

Member
We are developing an internal addon that deep dives into uploaded images in the Media Gallery using various tools to see if they need to be moderated, for example if they are inappropriate.

This is running in a cron job. For the life of me, I can't figure out how to generate a proper report. Here is the relevant code:
Code:
            $reportCreator = $app->service('XF:Report\Creator', 'xfmg_media', $media);
 

            if ($user) {
                $reportCreator->getCommentPreparer()->setUser($user);

                if ($reportCreator->getThreadCreator()) {
                    $reportCreator->getThreadCreator()->setUserAutomated($user);
                }
            }

            $reportCreator->setMessage($message);

            $reportCreator->content_info = [
                'album_id' => $media->album_id,
                'title' => $media->title,
                'description' => $media->description,
                'category_id' => $media->Category->category_id,
                'category_title' => $media->Category->title,
                'user_id' => $media->user_id,
                'username' => $media->username
            ];
         
            if (!$reportCreator->validate($errors)) {
                XF::logError('Could not report media: ' . implode(', ', $errors));
                return;
            }

            $save = $reportCreator->save();

This creates the report, in the specified forum, but the links in the post do not go to the media item. They will go to: https://mylocal.test/admin.php?media instead of https://mylocal.test/media/image-name.65851/

Any idea how to get this done?
 
Last edited:
I think the issue here is because it is firing in the admin area (running cron job there) that it doesn't pick up the media type properly when creating the report... Still at a loss..
 
Back
Top Bottom