42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Http\Controller;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Lucent\Account\Auth;
|
||
|
|
use Lucent\Channel\ChannelContext;
|
||
|
|
use Lucent\Record\RecordRepo;
|
||
|
|
use Lucent\Revision\RevisionRepo;
|
||
|
|
use Lucent\Schema\SchemaRepo;
|
||
|
|
use function Lucent\Response\fail;
|
||
|
|
use function Lucent\Response\ok;
|
||
|
|
|
||
|
|
class RevisionController extends Controller
|
||
|
|
{
|
||
|
|
|
||
|
|
public function index(Request $request)
|
||
|
|
{
|
||
|
|
|
||
|
|
$revisions = RevisionRepo::getByRecordId($request->route("rid"));
|
||
|
|
return ok($revisions);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function rollback(Request $request)
|
||
|
|
{
|
||
|
|
$schemas = SchemaRepo::all();
|
||
|
|
$revision = RevisionRepo::getByRecordIdAndVersion($request->route("rid"), (int)$request->route("version"));
|
||
|
|
|
||
|
|
try {
|
||
|
|
RecordRepo::replaceMany($schemas, [$revision->toDB()], Auth::currentUserId());
|
||
|
|
} catch (\Lucent\Schema\Validator\ValidatorException $th) {
|
||
|
|
return fail($th->getFirstValidatorError());
|
||
|
|
} catch (\Lucent\LucentException $th) {
|
||
|
|
return fail($th);
|
||
|
|
} catch (\Throwable $th) {
|
||
|
|
return fail($th);
|
||
|
|
}
|
||
|
|
return ok();
|
||
|
|
}
|
||
|
|
}
|