Skip to content

Commit

Permalink
change!: change the way to update code. RSYNC is not longer used. Now…
Browse files Browse the repository at this point in the history
…, a clean install and a backup of the old version in the backups directory (outside of httpdocs) is done.
  • Loading branch information
Paco committed Jan 22, 2025
1 parent 43d3bd4 commit f2e4855
Showing 1 changed file with 215 additions and 26 deletions.
241 changes: 215 additions & 26 deletions core/area_maintenance/class.area_maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -1352,38 +1352,227 @@ public static function update_code(object $options) : object {

// rsync
// CLI msg
if ( running_in_cli()===true ) {
print_cli((object)[
'msg' => 'Updating files',
'memory' => dd_memory_usage()
]);
}
if ( running_in_cli()===true ) {
print_cli((object)[
'msg' => 'Updating files',
'memory' => dd_memory_usage()
]);
}
$source = (strpos(DEDALO_SOURCE_VERSION_URL, 'github.com'))
? DEDALO_SOURCE_VERSION_LOCAL_DIR .'/dedalo-master' // like 'dedalo-master'
: DEDALO_SOURCE_VERSION_LOCAL_DIR .'/'. pathinfo($file_name)['filename']; // like 'dedalo_code' from 'dedalo_code.zip'
$target = DEDALO_ROOT_PATH;
$exclude = ' --exclude="*/config*" --exclude="media" ';
$additional = ''; // $is_preview===true ? ' --dry-run ' : '';
$command = 'rsync -avui --no-owner --no-group --no-perms --progress '. $exclude . $additional . $source.'/ ' . $target.'/';
$output = shell_exec($command);
if ($output===null) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing rsync command. source: '.$source;

// upgrade files
// copy downloaded folder to httpdocs like ../tmp/dedalo_code => ../httpdocs/dedalo_code
$command = "cp -R {$source} {$target}_code";
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output)
, logger::ERROR
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);

// copy config files
$files_to_copy = [
'config/config.php',
'config/config_db.php',
'config/config_areas.php',
'config/config_core.php'
];
foreach ($files_to_copy as $file_name) {

if (!copy("{$target}/$file_name", "{$target}_code/{$file_name}")){
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error on copy file: '.$file_name;
debug_log(__METHOD__
. " copy file error " . PHP_EOL
. " source " . "{$target}/$file_name" . PHP_EOL
. " target " . "{$target}_code/{$file_name}"
, logger::ERROR
);
return $response;
}else{
debug_log(__METHOD__
. " copy file success " . PHP_EOL
. " source " . "{$target}/$file_name" . PHP_EOL
. " target " . "{$target}_code/{$file_name}"
, logger::WARNING
);
}
}

// move media directory
$command = "mv {$target}/media {$target}_code/media";
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);

// tools
$dd_tools = [
'tool_cataloging',
'tool_common',
'tool_dd_label',
'tool_dev_template',
'tool_diffusion',
'tool_export',
'tool_hierarchy',
'tool_image_rotation',
'tool_import_dedalo_csv',
'tool_import_files',
'tool_import_marc21',
'tool_import_rdf',
'tool_import_zotero',
'tool_indexation',
'tool_lang',
'tool_lang_multi',
'tool_media_versions',
'tool_numisdata_epigraphy',
'tool_numisdata_order_coins',
'tool_pdf_extractor',
'tool_posterframe',
'tool_propagate_component_data',
'tool_qr',
'tool_subtitles',
'tool_tc',
'tool_time_machine',
'tool_tr_print',
'tool_transcription',
'tool_update_cache',
'tool_upload',
'tool_user_admin'
];

$tools_src = "{$target}/tools";
$old_tools = dir($tools_src);
while(($file = $old_tools->read()) !== false) {
if($file === "." || $file === "..") continue;
if( is_dir($tools_src .'/'. $file) && !in_array($file, $dd_tools) ) {

$command = "cp -R {$tools_src}/{$file} {$target}_code/tools/{$file}";
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);
}
}

// rename directory old version such as 'dedalo' => '../backup/code/dedalo_6.3.1'
$backup_code_path = DEDALO_BACKUP_PATH . '/code';
create_directory($backup_code_path);
$command = "mv $target {$backup_code_path}/dedalo_" .DEDALO_VERSION;
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);

// rename new version directory to final dir such as 'dedalo_code' => 'dedalo'
$command = "mv {$target}_code {$target}";
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);

// set permissions
$command = "chmod -R 750 {$target}";
exec($command, $output, $result_code);
if ($result_code!=0) {
$response->msg = 'Error. Request failed ['.__FUNCTION__.']. Error executing command: '.$command;
debug_log(__METHOD__
. $response->msg . PHP_EOL
. ' command: ' . to_string($command) . PHP_EOL
. ' output: ' . to_string($output) . PHP_EOL
. ' result_code: ' . to_string($result_code)
, logger::ERROR
);
return $response;
}
debug_log(__METHOD__
. " exec command" . PHP_EOL
. " command " . to_string($command) . PHP_EOL
. " output " . to_string($output) . PHP_EOL
. " result_code type " . gettype($result_code) . PHP_EOL
. " result_code " . to_string($result_code)
, logger::WARNING
);
return $response;
}
$result->rsync = [
"command: " . $command,
"output: " . str_replace(["\n","\r"], '<br>', $output),
];
debug_log(__METHOD__
." RSYNC command done ". PHP_EOL .to_string($command)
, logger::DEBUG
);

// remove temp used files and folders
$command_rm_dir = "rm -R -f $source";
Expand Down

0 comments on commit f2e4855

Please sign in to comment.