Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 921ce94

Browse files
author
the-djmaze
committed
Improved Nextcloud startApp() for #96
1 parent 9cca299 commit 921ce94

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,7 @@ public function registerHooks()
3434
public static function startApp(bool $api = false)
3535
{
3636
if (!\class_exists('RainLoop\\Api')) {
37-
if ($api) {
38-
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
39-
}
4037
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
41-
$_SERVER['SCRIPT_NAME'] = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/index.php';
42-
43-
$sData = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/';
44-
if (\is_dir($sData)) {
45-
\define('APP_DATA_FOLDER_PATH', $sData);
46-
}
4738

4839
// Nextcloud the default spl_autoload_register() not working
4940
\spl_autoload_register(function($sClassName){
@@ -53,7 +44,40 @@ public static function startApp(bool $api = false)
5344
}
5445
});
5546

56-
require_once \OC::$server->getAppManager()->getAppPath('snappymail') . '/app/index.php';
47+
$path = \OC::$server->getAppManager()->getAppPath('snappymail') . '/app/';
48+
49+
$sData = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/';
50+
if (!\is_file("{$path}include.php")) {
51+
\file_put_contents("{$path}include.php",
52+
\file_get_contents("{$path}_include.php")
53+
. "define('APP_DATA_FOLDER_PATH', '{$sData}');\n"
54+
);
55+
}
56+
// \define('APP_DATA_FOLDER_PATH', $sData);
57+
58+
if ($api) {
59+
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
60+
}
61+
62+
require_once "{$path}index.php";
63+
64+
if ($api) {
65+
$oConfig = \RainLoop\Api::Config();
66+
if (!$oConfig->Get('webmail', 'app_path')) {
67+
$oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/');
68+
$oConfig->Save();
69+
}
70+
/*
71+
if (!\is_dir(APP_PLUGINS_PATH . 'nextcloud')) {
72+
\SnappyMail\Repository::installPackage('plugin', 'nextcloud');
73+
$oConfig->Set('plugins', 'enable', true);
74+
$aList = \SnappyMail\Repository::getEnabledPackagesNames();
75+
$aList[] = 'nextcloud';
76+
$oConfig->Set('plugins', 'enabled_list', \implode(',', \array_unique($aList)));
77+
$oConfig->Save();
78+
}
79+
*/
80+
}
5781
}
5882
}
5983

0 commit comments

Comments
 (0)