Beispiel #1
0
 protected function getRecordExtras()
 {
     $emailService = Service::whereName('email')->first();
     $emailTemplateInvite = EmailTemplate::whereName('User Invite Default')->first();
     $emailTemplatePassword = EmailTemplate::whereName('Password Reset Default')->first();
     $emailTemplateOpenReg = EmailTemplate::whereName('User Registration Default')->first();
     return ['config' => ['allow_open_registration' => false, 'open_reg_email_service_id' => !empty($emailService) ? $emailService->id : null, 'open_reg_email_template_id' => !empty($emailTemplateOpenReg) ? $emailTemplateOpenReg->id : null, 'invite_email_service_id' => !empty($emailService) ? $emailService->id : null, 'invite_email_template_id' => !empty($emailTemplateInvite) ? $emailTemplateInvite->id : null, 'password_email_service_id' => !empty($emailService) ? $emailService->id : null, 'password_email_template_id' => !empty($emailTemplatePassword) ? $emailTemplatePassword->id : null]];
 }
Beispiel #2
0
 /**
  * Checks to see if a service already exists
  *
  * @param string $serviceName
  *
  * @return bool
  */
 protected function serviceExists($serviceName)
 {
     return Service::whereName($serviceName)->exists();
 }
Beispiel #3
0
 /**
  * Main retrieve point for each service
  *
  * @param string $name Which service (name) to retrieve.
  *
  * @return string
  * @throws NotFoundException
  */
 public function getSwaggerForService($name)
 {
     $cachePath = $name . '.json';
     if (null === ($content = \Cache::get($cachePath))) {
         $service = Service::whereName($name)->get()->first();
         if (empty($service)) {
             throw new NotFoundException("Service '{$name}' not found.");
         }
         $content = ['swaggerVersion' => static::SWAGGER_VERSION, 'apiVersion' => \Config::get('df.api_version', static::API_VERSION), 'basePath' => url('/api/v2')];
         try {
             $result = Service::getStoredContentForService($service);
             if (empty($result)) {
                 throw new NotFoundException("No Swagger content found.");
             }
             $content = array_merge($content, $result);
             $content = json_encode($content, JSON_UNESCAPED_SLASHES);
             // replace service type placeholder with api name for this service instance
             $content = str_replace('{api_name}', $name, $content);
             // cache it for later access
             \Cache::forever($cachePath, $content);
         } catch (\Exception $ex) {
             \Log::error("  * System error creating swagger file for service '{$name}'.\n{$ex->getMessage()}");
         }
     }
     return $content;
 }
Beispiel #4
0
 /**
  * Package schemas for export.
  *
  * @return bool
  * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
  */
 private function packageSchemas()
 {
     if (!empty($this->exportSchemas)) {
         $schemas = [];
         foreach ($this->exportSchemas as $serviceName => $component) {
             if (is_array($component)) {
                 $component = implode(',', $component);
             }
             if (is_numeric($serviceName)) {
                 /** @type Service $service */
                 $service = Service::find($serviceName);
             } else {
                 /** @type Service $service */
                 $service = Service::whereName($serviceName)->whereDeletable(1)->first();
             }
             if (!empty($service) && !empty($component)) {
                 if ($service->type === 'sql_db') {
                     $schema = ServiceHandler::handleRequest(Verbs::GET, $serviceName, '_schema', ['ids' => $component]);
                     $schemas[] = ['name' => $serviceName, 'table' => $this->resourceWrapped ? $schema[$this->resourceWrapper] : $schema];
                 }
             }
         }
         if (!empty($schemas) && !$this->zip->addFromString('schema.json', json_encode(['service' => $schemas], JSON_UNESCAPED_SLASHES))) {
             throw new InternalServerErrorException("Can not include database schema in package file.");
         }
         return true;
     }
     return false;
 }
 protected function createDbService($num)
 {
     $serviceName = 'db' . $num;
     $service = \DreamFactory\Core\Models\Service::whereName($serviceName)->first();
     if (empty($service)) {
         $service = \DreamFactory\Core\Models\Service::create(["name" => $serviceName, "label" => "Database" . $num, "description" => "Local Database" . $num, "is_active" => true, "type" => "sql_db", 'config' => ['dsn' => 'foo', 'username' => 'user', 'password' => 'password', 'db' => 'mydb', 'options' => 'options', 'attributes' => 'attributes']]);
     }
     return $service->id;
 }