clientService = $clientService; $this->config = $config; $this->connection = $connection; $this->phpIni = $phpIni; $this->l = $l; } protected function registerCategories() { $this->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() { $this->registerCategories(); $categories = []; foreach ($this->categories as $category) { $categories[$category->getCategory()] = [ 'displayName' => $category->getDisplayName(), 'enabled' => $this->config->getAppValue('survey_client', $category->getCategory(), 'yes') === 'yes', ]; } return $categories; } /** * @return array */ public function getReport() { $this->registerCategories(); $tuples = []; foreach ($this->categories as $category) { if ($this->config->getAppValue('survey_client', $category->getCategory(), 'yes') === 'yes') { 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->config->setAppValue('survey_client', 'last_sent', (string)time()); $this->config->setAppValue('survey_client', 'last_report', json_encode($report)); return new DataResponse( $report ); } return new DataResponse( $report, Http::STATUS_INTERNAL_SERVER_ERROR ); } }