title = 'Default Board'; $board->account = new NullAccount(1); $board->status = DashboardBoardStatus::ACTIVE; DashboardBoardMapper::create()->execute($board); } /** * Install data from providing modules. * * The data can be either directories which should be created or files which should be "uploaded" * * @param ApplicationAbstract $app Application * @param array $data Additional data * * @return array * * @throws PathException * @throws \Exception * * @since 1.0.0 */ public static function installExternal(ApplicationAbstract $app, array $data) : array { if (!\is_file($data['path'] ?? '')) { throw new PathException($data['path'] ?? ''); } $dashboardFile = \file_get_contents($data['path'] ?? ''); if ($dashboardFile === false) { throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore } $dashboardData = \json_decode($dashboardFile, true) ?? []; if ($dashboardData === false) { throw new \Exception(); // @codeCoverageIgnore } $result = [ 'component' => [], ]; $apiApp = new class() extends ApplicationAbstract { protected string $appName = 'Api'; }; $apiApp->dbPool = $app->dbPool; $apiApp->unitId = $app->unitId; $apiApp->accountManager = $app->accountManager; $apiApp->appSettings = $app->appSettings; $apiApp->moduleManager = $app->moduleManager; $apiApp->eventManager = $app->eventManager; /** @var array $dashboardData */ foreach ($dashboardData as $dashboard) { switch ($dashboard['type']) { case 'component': $result['component'][] = self::createComponent($apiApp, $dashboard); break; default: } } return $result; } /** * Create board component. * * @param ApplicationAbstract $app Application * @param array $data Type info * * @return array * * @since 1.0.0 */ private static function createComponent(ApplicationAbstract $app, array $data) : array { $module = $app->moduleManager->get('Dashboard'); $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('board', (int) ($data['board'] ?? 0)); $request->setData('order', (int) ($data['order'] ?? 0)); $request->setData('module', (string) ($data['module'] ?? '')); $module->apiComponentCreate($request, $response); $responseData = $response->getData(''); if (!\is_array($responseData)) { return []; } return \is_array($responseData['response']) ? $responseData['response'] : $responseData['response']->toArray(); } }