categories[] = new Server( $this->config, $this->l ); $this->categories[] = new Php( $this->phpIni, $this->l ); $this->categories[] = new Database( $this->config, $this->connection, $this->l ); $this->categories[] = new Apps( $this->connection, $this->l ); $this->categories[] = new Stats( $this->connection, $this->l ); $this->categories[] = new FilesSharing( $this->connection, $this->l ); $this->categories[] = new Encryption( $this->config, $this->l ); } /** * @return array */ public function getCategories(): array { $this->registerCategories(); $categories = []; foreach ($this->categories as $category) { $categories[$category->getCategory()] = [ 'displayName' => $category->getDisplayName(), 'enabled' => $this->appConfig->getAppValueBool($category->getCategory(), true), ]; } return $categories; } /** * @return array{id: string, items: array} */ public function getReport() { $this->registerCategories(); $tuples = []; foreach ($this->categories as $category) { if ($this->appConfig->getAppValueBool($category->getCategory(), true)) { foreach ($category->getData() as $key => $value) { $tuples[] = [ $category->getCategory(), $key, $value ]; } } } return [ 'id' => $this->config->getSystemValue('instanceid'), 'items' => $tuples, ]; } /** * @return DataResponse */ public function sendReport(): DataResponse { $report = $this->getReport(); $client = $this->clientService->newClient(); try { $response = $client->post(self::SURVEY_SERVER_URL . 'ocs/v2.php/apps/survey_server/api/v1/survey', [ 'timeout' => 5, 'query' => [ 'data' => json_encode($report), ], ]); } catch (\Exception $e) { return new DataResponse( $report, Http::STATUS_INTERNAL_SERVER_ERROR ); } if ($response->getStatusCode() === Http::STATUS_OK) { $this->appConfig->setAppValueInt('last_sent', $this->timeFactory->getTime()); $this->appConfig->setAppValueString('last_report', json_encode($report), true); return new DataResponse( $report ); } return new DataResponse( $report, Http::STATUS_INTERNAL_SERVER_ERROR ); } }