<?php

\session_start();
\ob_start();
require __DIR__ . '/common.php';
use Ministra\Lib\Admin;
use Ministra\Lib\AdminAccess;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e;
use Ministra\Lib\Video;
use Ministra\Lib\VideoMaster;
$error = '';
\Ministra\Lib\Admin::checkAuth();
\Ministra\Lib\Admin::checkAccess(\Ministra\Lib\AdminAccess::ACCESS_VIEW);
if (@$_GET['id']) {
    $task_id = (int) $_GET['id'];
    \Ministra\Lib\Admin::checkAccess(\Ministra\Lib\AdminAccess::ACCESS_EDIT);
    $task = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->from('moderator_tasks')->where(['id' => $task_id])->get()->first();
    $moderator_id = $task['to_usr'];
    $video_id = $task['media_id'];
    $action = "<a href=\\'msgs.php?task={$task_id}\\'>" . \_('task done') . '</a>';
    \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->insert('video_log', ['action' => $action, 'video_id' => $video_id, 'moderator_id' => $moderator_id, 'actiontime' => 'NOW()']);
    \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->update('moderator_tasks', ['ended' => 1, 'end_time' => 'NOW()'], ['id' => (int) $_GET['id']]);
    $video = \Ministra\Lib\Video::getById($video_id);
    $path = $video['path'];
    $master = new \Ministra\Lib\VideoMaster();
    try {
        $master->startMD5SumInAllStorages($path);
    } catch (\Exception $exception) {
    }
    \header('Location: tasks.php');
    exit;
}
