23 lines
4.0 KiB
PHP
23 lines
4.0 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');
|
|
set_exception_handler(function(Throwable $e){fwrite(STDERR,'Destination preflight 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['driver']!=='pgsql'||!empty($c['url'])||!in_array($c['host'],['127.0.0.1','localhost'])||(int)$c['port']!==5432||$c['database']!=='investemoz')throw new RuntimeException('Destination identity differs');
|
|
$pdo=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$pdo->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
|
|
try {
|
|
$target=$pdo->query('SELECT current_database() AS database,inet_server_port() AS port')->fetch(PDO::FETCH_ASSOC);
|
|
if($target['database']!=='investemoz'||(int)$target['port']!==5432)throw new RuntimeException('Actual destination differs');
|
|
$input=json_decode(file_get_contents(__DIR__.'/B-final-inputs-20261015.json'),true,512,JSON_THROW_ON_ERROR);
|
|
$files=[];foreach($input['source_files']as$n=>$hash){$p=$root.'/'.$n;$files[$n]=['exists'=>is_file($p),'destination_sha256'=>is_file($p)?hash_file('sha256',$p):null,'candidate_sha256'=>$hash,'replace_required'=>!is_file($p)||hash_file('sha256',$p)!==$hash];}
|
|
$build=[];$dir=$root.'/public/build';$it=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,FilesystemIterator::SKIP_DOTS));foreach($it as$f)if($f->isFile()){$rel=str_replace('\\','/',substr($f->getPathname(),strlen($dir)+1));$build[$rel]=hash_file('sha256',$f->getPathname());}ksort($build);
|
|
$schema=$pdo->query("SELECT table_schema,table_name,column_name,ordinal_position,data_type,udt_name,is_nullable,column_default FROM information_schema.columns WHERE table_schema='public' ORDER BY table_name,ordinal_position")->fetchAll(PDO::FETCH_ASSOC);
|
|
$migrations=$pdo->query('SELECT migration,batch FROM migrations ORDER BY migration')->fetchAll(PDO::FETCH_ASSOC);
|
|
$flags=[];foreach(Dotenv\Dotenv::parse(file_get_contents($root.'/.env'))as$k=>$v)if(preg_match('/^(?:PORTAL|INVESTMOZ|COUNTRY).*?(?:ENABLED|RESTORE|RESTORATION|SHARING|WORKFLOW|PROFILE)/',$k)&&in_array(strtolower((string)$v),['true','false','0','1'],true))$flags[$k]=$v;
|
|
$protected=[];foreach(['.env','config/inertia.php','bootstrap/app.php','bootstrap/providers.php','composer.json','composer.lock','package.json','package-lock.json','vendor/composer/installed.json','public/index.php']as$n)if(is_file($root.'/'.$n))$protected[$n]=hash_file('sha256',$root.'/'.$n);
|
|
$p=['at'=>gmdate('c'),'candidate'=>'B-final-fabf722bc8c6','destination_root'=>$root,'target'=>$target,'SQL_read_only'=>true,'application_url'=>config('app.url'),'PHP_CLI'=>PHP_VERSION,'config_cached'=>$app->configurationIsCached(),'route_cache_exists'=>is_file($root.'/bootstrap/cache/routes-v7.php'),'sources'=>$files,'current_build_files'=>$build,'protected_configuration_and_dependencies'=>$protected,'boolean_flags_preserved'=>$flags,'inertia_devtools_enabled'=>config('inertia.devtools.enabled'),'schema_sha256'=>hash('sha256',json_encode($schema,JSON_THROW_ON_ERROR)),'schema_columns'=>$schema,'migrations_sha256'=>hash('sha256',json_encode($migrations,JSON_THROW_ON_ERROR)),'migration_count'=>count($migrations),'destination_business_data_read'=>false,'source_writes'=>0,'active_changes'=>0,'activation_authorized'=>false];
|
|
file_put_contents(__DIR__.'/B-destination-preflight-readonly-20261015.json',json_encode($p,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['target'=>$target,'URL'=>$p['application_url'],'sources'=>count($files),'build_files'=>count($build),'migrations'=>count($migrations),'config_cached'=>$p['config_cached'],'devtools'=>$p['inertia_devtools_enabled'],'active_changes'=>0]);
|
|
}finally{$pdo->exec('ROLLBACK');}
|