Skip to content

Commit

Permalink
Hotfix for bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Nov 3, 2024
1 parent f200156 commit f152904
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use OCA\OpenCatalogi\Dashboard\UnpublishedPublicationsWidget;
use OCA\OpenCatalogi\Dashboard\UnpublishedAttachmentsWidget;
use OCP\IConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\AppFramework\App\IAppManager;

use OCP\App\AppManager;
/**
* Main Application class for OpenCatalogi
*/
Expand All @@ -35,36 +33,29 @@ public function register(IRegistrationContext $context): void {

public function boot(IBootContext $context): void {
$container = $context->getServerContainer();

/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->get(IEventDispatcher::class);
/** @var IAppManager $appManager */
$appManager = $container->get(IAppManager::class);

// Listen for app enable event
$dispatcher->addListener(IAppManager::EVENT_APP_ENABLE, function() use ($container) {
// Only proceed if it's our app being enabled
if ($appManager->isInstalled(self::APP_ID)) {
// Get app config to check if initial sync has been done
$config = $container->get(IConfig::class);
$initialSyncDone = $config->getAppValue(self::APP_ID, 'initial_sync_done', 'false');

// Only run if initial sync hasn't been done
if ($initialSyncDone === 'false') {
try {
// Get DirectoryService and run sync
$directoryService = $container->get(\OCA\OpenCatalogi\Service\DirectoryService::class);
$directoryService->doCronSync();

// Mark initial sync as done
$config->setAppValue(self::APP_ID, 'initial_sync_done', 'true');
} catch (\Exception $e) {
\OC::$server->getLogger()->error('Failed to run initial directory sync: ' . $e->getMessage(), [
'app' => self::APP_ID
]);
}
// @TODO: This should only run if the app is enabled for the user
//$appManager = $container->get(AppManager::class);
//if($appManager->isEnabledForUser('opencatalogi')){
// Get app config to check if initial sync has been done
$config = $container->get(IConfig::class);
$initialSyncDone = $config->getAppValue(self::APP_ID, 'initial_sync_done', 'false');

// Only run if initial sync hasn't been done
if ($initialSyncDone === 'false') {
try {
// Get DirectoryService and run sync
$directoryService = $container->get(\OCA\OpenCatalogi\Service\DirectoryService::class);
$directoryService->doCronSync();

// Mark initial sync as done
$config->setAppValue(self::APP_ID, 'initial_sync_done', 'true');
} catch (\Exception $e) {
\OC::$server->getLogger()->error('Failed to run initial directory sync: ' . $e->getMessage(), [
'app' => self::APP_ID
]);
}
}
});
}
//}
}
}

0 comments on commit f152904

Please sign in to comment.