Skip to content

Commit

Permalink
dev/wordpress#66 Re-instate newer variables but with more support for…
Browse files Browse the repository at this point in the history
… legacy file systems
  • Loading branch information
seamuslee001 committed Aug 4, 2020
1 parent da6c68c commit 34e68d7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ protected function registerPathVars():void {
'url' => admin_url('admin.php'),
];
});
Civi::paths()->register('civicrm.files', function () {
$upload_dir = wp_get_upload_dir();

$old = CRM_Core_Config::singleton()->ufSystem->getDefaultFileStorage();
$new = [
'path' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR,
'url' => $upload_dir['baseurl'] . '/civicrm/',
];

if ($old['path'] === $new['path']) {
return $new;
}

$oldExists = file_exists($old['path']);
$newExists = file_exists($new['path']);

if ($oldExists && !$newExists) {
return $old;
}
elseif (!$oldExists && $newExists) {
return $new;
}
elseif (!$oldExists && !$newExists) {
// neither exists. but that's ok. we're in one of these two cases:
// - we're just starting installation... which will get sorted in a moment
// when someone calls mkdir().
// - we're running a bespoke setup... which will get sorted in a moment
// by applying $civicrm_paths.
return $new;
}
elseif ($oldExists && $newExists) {
// situation ambiguous. encourage admin to set value explicitly.
if (!isset($GLOBALS['civicrm_paths']['civicrm.files'])) {
\Civi::log()->warning("The system has data from both old+new conventions. Please use civicrm.settings.php to set civicrm.files explicitly.");
}
return $new;
}
});
}
else {
// Legacy support - only relevant for older extern routes.
Expand Down

0 comments on commit 34e68d7

Please sign in to comment.