14 lines
1.4 KiB
PHP
14 lines
1.4 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');
|
|
set_exception_handler(function(Throwable $e){fwrite(STDERR,'Read-only scope stopped: '.$e::class.' line '.$e->getLine().PHP_EOL);exit(1);});
|
|
$root=dirname(__DIR__,2);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';
|
|
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
|
|
$c=config('database.connections.'.config('database.default'));
|
|
if($c['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost'])||!empty($c['url']))throw new RuntimeException('Active guard');
|
|
$db=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$db->exec('BEGIN READ ONLY');
|
|
try{
|
|
$rows=$db->query('SELECT id,owner_user_id,modality,status,version_no FROM existing_businesses WHERE deleted_at IS NULL ORDER BY id')->fetchAll(PDO::FETCH_ASSOC);
|
|
$p=['read_only'=>true,'actor_requested'=>2,'existing_businesses'=>$rows,'new_records_created'=>0,'grants_changed'=>0];
|
|
if(is_file(__DIR__.'/AMBITO-ATUAL-READONLY.json'))throw new RuntimeException('Preserve proof');file_put_contents(__DIR__.'/AMBITO-ATUAL-READONLY.json',json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode($p).PHP_EOL;
|
|
}finally{$db->exec('ROLLBACK');}
|