removed hard-coded environment paths; updated .env

there were places in the codebase where path to fipamo specific paths
and file were hard-coded into the system, reducing flexibility and
customozation for people that want to define their own path.

those hard-coded elements have been removed and replaced with references
to the env file so those paths can be changed to whatever is needed

the .env.example file has also been updated to contain default paths for
easier installation.
This commit is contained in:
ro 2024-06-12 14:53:10 -06:00
parent e0994b32ab
commit 59b9f481af
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
4 changed files with 46 additions and 39 deletions

View file

@ -61,8 +61,14 @@ VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
#------------------ #------------------
# FIPAMO SETTINGS # FIPAMO SETTINGS
#------------------ #------------------
PAGES_PATH="path/to/pages" FIPAMO_DIR="../content"
THEMES_PATH="path/to/themes" PAGES_PATH="${FIPAMO_DIR}/pages"
SETTINGS_PATH="path/to/settings.json" THEMES_PATH="${FIPAMO_DIR}/themes"
FOLKS_PATH="path/to/folks.json" FIPAMO_CONFIG="${FIPAMO_DIR}/config"
TAGS_PATH="path/to/tag.json" SETTINGS_PATH="${FIPAMO_CONFIG}/settings.json"
FOLKS_PATH="${FIPAMO_CONFIG}/folks.json"
TAGS_PATH="${FIPAMO_CONFIG}/tags.json"
FIPAMO_INIT="${FIPAMO_DIR}/init"
FIPAMO_BACKUPS="${FIPAMO_DIR}/backups"
# MAIL
ADMIN_EMAIL = "you@admin.email"

View file

@ -21,7 +21,7 @@ class MemberRepository implements MemberRepositoryInterface
if (file_exists(env('FOLKS_PATH'))) { if (file_exists(env('FOLKS_PATH'))) {
$this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true);
} else { } else {
$this->folks = json_decode(file_get_contents('../content/init/folks-template.json'), true); $this->folks = json_decode(file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'), true);
} }
} }

View file

@ -52,11 +52,11 @@ class InitService
//grab template files //grab template files
//TODO: Remove hardcoded link and set up init path in settings //TODO: Remove hardcoded link and set up init path in settings
$newFolks = json_decode( $newFolks = json_decode(
file_get_contents('../content/init/folks-template.json'), file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'),
true true
); );
$newSettings = json_decode( $newSettings = json_decode(
file_get_contents('../content/init/settings-template.json'), file_get_contents(env('FIPAMO_INIT') . '/settings-template.json'),
true true
); );
//get form values //get form values
@ -82,6 +82,7 @@ class InitService
$newSettings['global']['title'] = $title; $newSettings['global']['title'] = $title;
//create index file //create index file
//TODO: upate path attribute to use env variable
$index = [ $index = [
'id' => 1, 'id' => 1,
'uuid' => createUUID(), 'uuid' => createUUID(),
@ -103,16 +104,16 @@ class InitService
]; ];
//once all files created, write down //once all files created, write down
mkdir('../content/config', 0755, true); mkdir(env('FIPAMO_CONFIG'), 0755, true);
$this->docs->writeSettings($newSettings, '../content/config/settings.json'); $this->docs->writeSettings($newSettings, env('FIPAMO_CONFIG') . '/settings.json');
$this->docs->writeSettings($newFolks, '../content/config/folks.json'); $this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json');
$this->docs->writeSettings([], '../content/config/tags.json'); $this->docs->writeSettings([], env('FIPAMO_CONFIG') . '/tags.json');
$object = (object) $index; $object = (object) $index;
$this->docs->writePages( $this->docs->writePages(
'create', 'create',
'start', 'start',
'../content/pages/start/index.md', env('PAGES_PATH') . '/start/index.md',
$this->docs::objectToMD($object) $this->docs::objectToMD($object)
); );
@ -124,11 +125,11 @@ class InitService
public function restore($request) public function restore($request)
{ {
$file = $request->file('backup-upload'); $file = $request->file('backup-upload');
$file->move('../content' . '/', $file->getClientOriginalName()); $file->move(env('FIPAMO_DIR') . '/', $file->getClientOriginalName());
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$result = []; $result = [];
$tempDir = '../content/_temp'; $tempDir = env('FIPAMO_DIR') . '/_temp';
if ($zip->open('../content' . '/' . $file->getClientOriginalName()) === true) { if ($zip->open(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName()) === true) {
$folks = json_decode($zip->getFromName('config/folks.json'), true); $folks = json_decode($zip->getFromName('config/folks.json'), true);
$found = find($folks, ['handle' => $request->restore_member_handle]); $found = find($folks, ['handle' => $request->restore_member_handle]);
if ($found) { if ($found) {
@ -153,18 +154,18 @@ class InitService
$newConfig['global']['externalAPI'] = 'false'; $newConfig['global']['externalAPI'] = 'false';
} }
//make dir and write new config files //make dir and write new config files
if (!is_dir('../content/config/')) { if (!is_dir(env('FIPAMO_CONFIG'))) {
mkdir('../content/config/', 0755, true); mkdir(env('FIPAMO_CONFIG'), 0755, true);
} }
$this->docs->writeSettings($newConfig, '../content/config/settings.json'); $this->docs->writeSettings($newConfig, env('FIPAMO_CONFIG') . '/settings.json');
$this->docs->writeSettings($newFolks, '../content/config/folks.json'); $this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json');
rename($tempDir . '/config/tags.json', '../content/config/tags.json'); rename($tempDir . '/config/tags.json', env('FIPAMO_CONFIG') . '/tags.json');
//move saved markdown pages //move saved markdown pages
rename($tempDir . '/content/pages/', '../content/pages'); rename($tempDir . '/content/pages/', env('PAGES_PATH'));
//clean up temp dir and zip file //clean up temp dir and zip file
$this->docs::deleteFolder($tempDir); $this->docs::deleteFolder($tempDir);
$zip->close(); $zip->close();
unlink('../content/' . $file->getClientOriginalName()); unlink(env('FIPAMO_DIR') . $file->getClientOriginalName());
$result = [ $result = [
'type' => 'requestGood', 'type' => 'requestGood',
'message' => 'Site Restored! Redirecting', 'message' => 'Site Restored! Redirecting',

View file

@ -18,18 +18,18 @@ class MaintenanceService
{ {
//make sure back directory is there //make sure back directory is there
$stamp = Carbon::now()->format("YmdGis"); $stamp = Carbon::now()->format("YmdGis");
if (!is_dir('../content/backups')) { if (!is_dir(env('FIPAMO_BACKUPS'))) {
mkdir('../content/backups', 0755, true); mkdir(env('FIPAMO_BACKUPS'), 0755, true);
} }
//creat backup zip //creat backup zip
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$zip->open( $zip->open(
'../content/backups/backup-' . $stamp . '.zip', env('FIPAMO_BACKUPS') . '/backup-' . $stamp . '.zip',
\ZipArchive::CREATE | \ZipArchive::OVERWRITE \ZipArchive::CREATE | \ZipArchive::OVERWRITE
); );
//gather data and path info for md pages //gather data and path info for md pages
$pagePath = '../content/pages'; $pagePath = env('PAGES_PATH');
$yearPaths = glob($pagePath . '/*', GLOB_ONLYDIR); $yearPaths = glob($pagePath . '/*', GLOB_ONLYDIR);
foreach ($yearPaths as $years) { foreach ($yearPaths as $years) {
$year = explode('/', $years); $year = explode('/', $years);
@ -94,22 +94,22 @@ class MaintenanceService
$zip->addFile(env('FOLKS_PATH'), 'config/folks.json'); $zip->addFile(env('FOLKS_PATH'), 'config/folks.json');
$zip->addFile(env('TAGS_PATH'), 'config/tags.json'); $zip->addFile(env('TAGS_PATH'), 'config/tags.json');
// create temp files for image lists // create temp files for image lists
file_put_contents('../content/backups/blog_images_temp.json', json_encode($blogImages)); file_put_contents(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', json_encode($blogImages));
file_put_contents('../content/backups/user_images_temp.json', json_encode($userImages)); file_put_contents(env('FIPAMO_BACKUPS') . '/user_images_temp.json', json_encode($userImages));
file_put_contents('../content/backups/blog_docs_temp.json', json_encode($blogDocs)); file_put_contents(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', json_encode($blogDocs));
file_put_contents('../content/backups/blog_vids_temp.json', json_encode($blogVids)); file_put_contents(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', json_encode($blogVids));
//add to zip //add to zip
$zip->addFile('../content/backups/blog_images_temp.json', 'assets/blog_images.json'); $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', 'assets/blog_images.json');
$zip->addFile('../content/backups/user_images_temp.json', 'assets/user_images.json'); $zip->addFile(env('FIPAMO_BACKUPS') . '/user_images_temp.json', 'assets/user_images.json');
$zip->addFile('../content/backups/blog_docs_temp.json', 'assets/blog_docs.json'); $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', 'assets/blog_docs.json');
$zip->addFile('../content/backups/blog_vids_temp.json', 'assets/blog_videos.json'); $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', 'assets/blog_videos.json');
//save zip file //save zip file
$zip->close(); $zip->close();
//clean up temp files //clean up temp files
unlink('../content/backups/blog_images_temp.json'); unlink(env('FIPAMO_BACKUPS') . '/blog_images_temp.json');
unlink('../content/backups/user_images_temp.json'); unlink(env('FIPAMO_BACKUPS') . '/user_images_temp.json');
unlink('../content/backups/blog_docs_temp.json'); unlink(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json');
unlink('../content/backups/blog_vids_temp.json'); unlink(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json');
//update settings file with latest back up date //update settings file with latest back up date
$this->settings->updateGlobalData('last_backup', $stamp); $this->settings->updateGlobalData('last_backup', $stamp);