@param ModelInterface $model

@throws RuntimeException
181970
public function upload(ModelInterface $model)
    {
        if (!$this->isUploadable()) {
            return;
        }

        if (!is_dir($this->dirPath)) {
            mkdir($this->dirPath, 0777, true);
        }

        $file = null;
        foreach ($this->fields as $key => $field) {
            $getter = CamelCaser::underScoresToCamelCase('get_'.$field);

            if (method_exists($model, $getter)) {
                /** @var UploadedFile $file */
                $file = call_user_func_array(array($model, $getter), array());
            }

            if ($file instanceof UploadedFile) {
                if ($file->isExecutable()) {
                    throw new RuntimeException(sprintf('message.upload_executable'));
                }

                $filterUpload = new FilterUploadEvent();
                $filterUpload->setFileUploaded($file);

                $this->eventSubscriber->subscribe(Constants::PRE_UPLOAD, $filterUpload);

                $file = $filterUpload->getFileUploaded();
                $fileName = sha1(uniqid('SIAB_', true)).'.'.$file->getClientOriginalExtension();
                $file->move($this->dirPath, $fileName);

                $this->eventSubscriber->subscribe(Constants::POST_UPLOAD, $filterUpload);

                $setter = CamelCaser::underScoresToCamelCase('set_'.$this->targetFields[$key]);
                if (method_exists($model, $setter)) {
                    call_user_func_array(array($model, $setter), array($fileName));
                }
            }
        }
    }
809225
protected function deleteActionInternal(ModelInterface $entity) {
        $this->setStatusCode(204);
        $delete = new Delete($entity);
        $delete->process($this->getAcl());
    }
539065
public function setDateTime(\DateTimeInterface $dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            $immutable = new \DateTimeImmutable('@'.$dateTime->getTimestamp());
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
        }
        $this->dateTime = $dateTime;
    }
1276741
public function save(Driver $driver, ModelInterface $model)
    {
        $this->managerFactory->setModelClass(get_class($model));
        $manager = $this->managerFactory->getManager($driver);
        $preSaveEvent = new FilterModelEvent();
        $preSaveEvent->setModel($model);
        $preSaveEvent->setManager($manager);
        $this->eventSubscriber->subscribe(Constants::PRE_SAVE, $preSaveEvent);

        try {
            $manager->save($preSaveEvent->getModel());

            $postSaveEvent = new FilterModelEvent();
            $postSaveEvent->setManager($manager);
            $postSaveEvent->setModel($model);
            $this->eventSubscriber->subscribe(Constants::POST_SAVE, $postSaveEvent);
        } catch (\Exception $exception) {
            $this->errorMessage = 'message.save_failed';

            return false;
        }

        return true;
    }
651622
public function dropTable(ModelInterface $model)
    {
        $i = 0;

        $model->setConnection($this->connection);

        $builder = $this->getQueryBuilder();

//        $this->connection->executeUpdate($adapter->sqlCheckIntegrity(false, 'public', $model->tableName()));

        $schemaManager = $this->connection->getSchemaManager();
        foreach ($model->getMeta()->getManyToManyFields() as $field) {
            if (null === $field->through) {
                $fieldTable = TableNameResolver::getTableName($field->getTableName());
                if ($this->hasTable($fieldTable)) {
                    $schemaManager->dropTable($builder->getQuotedName($fieldTable));
                    $i += 1;
                }
            }
        }

        if ($this->hasTable($model->tableName())) {
            $schemaManager->dropTable($model->tableName());
            $i += 1;
        }

//        $this->connection->executeUpdate($adapter->sqlCheckIntegrity(true, 'public', $model->tableName()));

        return $i;
    }
1223725
protected function afterSave(EntityInterface $entity): void
    {
        $argv = compact('entity');
        $argv = $this->getEventManager()->prepareArgs($argv);

        $this->getEventManager()->trigger("{$this->event_prefix}_save_after", $this, $argv);
        if ($this->entity_event_prefix) {
            $this->getEventManager()->trigger("{$this->entity_event_prefix}_save_after", $this, $argv);
        }
    }
1327210
public function setModel(Model $model)
    {
        if (($content = $this->getContent()) instanceof WithModelInterface) {
            $content->setModel($model);
        }

        return $this;
    }
933426
protected function execute(CommandInterface $command)
    {
        $runner = $this->getCommandRunner();

        $this->lastReturnValue = $runner->run($command);

        $this->checkReturnValue($runner);
    }
383700
public function initialize(ContextInterface $context)
    {
        $context->setDatabase($this->databaseName);
        $context->setAjaxSteps($this->ajaxSteps);
        $context->setAjaxTimeout($this->ajaxTimeout);
        $context->setScreenshotPath($this->screenshotPath);
        $context->setRegionMap($this->regionMap);
        $context->setAdminUrl($this->adminUrl);
        $context->setLoginUrl($this->loginUrl);
    }
278466
public function pasteAfter(ModelInterface $previousModel, CollectionInterface $models, $sortedBy)
    {
        if (0 === $models->length()) {
            throw new \RuntimeException('No models passed to pasteAfter().');
        }
        $environment = $this->getEnvironment();

        if (\in_array(
            $environment
                ->getDataDefinition()
                ->getBasicDefinition()
                ->getMode(),
            [
                BasicDefinitionInterface::MODE_HIERARCHICAL,
                BasicDefinitionInterface::MODE_PARENTEDLIST
            ]
        )) {
            if (!$this->relationshipManager->isRoot($previousModel)) {
                $parentModel = $this->modelCollector->searchParentOf($previousModel);
                $parentName  = $parentModel->getProviderName();
                $this->relationshipManager->setSameParentForAll($models, $previousModel, $parentName);
            } else {
                $this->relationshipManager->setAllRoot($models);
            }
        }

        // Enforce proper sorting now.
        $siblings = $this->modelCollector->collectSiblingsOf($previousModel, $sortedBy);
        $newList  = (new SortingManager($models, $siblings, $sortedBy, $previousModel))->getResults();

        $environment->getDataProvider($previousModel->getProviderName())->saveEach($newList);
    }
161087
public function remove(Driver $driver, ModelInterface $model)
    {
        $this->managerFactory->setModelClass(get_class($model));
        $manager = $this->managerFactory->getManager($driver);
        $event = new FilterModelEvent();
        $event->setModel($model);
        $event->setManager($manager);
        $this->eventSubscriber->subscribe(Constants::PRE_DELETE, $event);

        /** @var JsonResponse $response */
        if ($response = $event->getResponse() instanceof JsonResponse) {
            $content = json_decode($response->getContent(), true);
            $this->errorMessage = isset($content['message']) ? $content['message'] : 'message.delete_failed';

            return false;
        }

        try {
            $manager->remove($model);
        } catch (\Exception $exception) {
            $this->errorMessage = 'message.delete_failed';

            return false;
        }

        return true;
    }
1058517
protected function initializeView(ViewInterface $view): void
    {
        $view->assignMultiple([
            'view' => $this->browserState->get('view'),
            'sortBy' => $this->browserState->get('sortBy'),
            'sortDirection' => $this->browserState->get('sortDirection'),
            'filter' => $this->browserState->get('filter'),
            'activeTag' => $this->browserState->get('activeTag'),
            'activeAssetCollection' => $this->browserState->get('activeAssetCollection'),
            'assetSources' => $this->assetSources,
            'variantsTabFeatureEnabled' => $this->settings['features']['variantsTab']['enable']
        ]);
    }
481453
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->fm = $this->model->loadFunctionMap();
    }
556350
public function setRoot(ModelInterface $model)
    {
        if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->mode) {
            return;
        }

        $condition = $this->relationships->getRootCondition();
        if (!$condition instanceof RootConditionInterface) {
            throw new DcGeneralRuntimeException('No root condition defined');
        }

        $condition->applyTo($model);
    }
445082
private function insertModelIntoDatabase(ModelInterface $model, $timestamp = 0)
    {
        $data = $this->convertModelToDataPropertyArray($model, $timestamp);
        if ($this->getIdGenerator()) {
            $model->setId($this->getIdGenerator()->generate());
            $data[$this->idProperty] = $model->getId();
        }

        $this->connection->insert($this->source, $data);

        $insertId = $this->connection->lastInsertId($this->source);

        if (('' !== $insertId) && !isset($data[$this->idProperty])) {
            $model->setId($insertId);
        }
    }
994367
public function create(ModelInterface $model)
    {
        $posttype = $this->container->make(PosttypeSingularity::class);

        $posttype
            ->setModel($model)
            ->boot();

        return $posttype;
    }
1341319
private function processPasteTopAfterModel(CollectionInterface $models, ModelIdInterface $parent = null)
    {
        if ($parent && $models->count()) {
            $manualSorting = ViewHelpers::getManualSortingProperty($this->getEnvironment());

            if ($manualSorting) {
                $this->pasteTop($models, $manualSorting, $parent);

                return;
            }

            $dataProvider = $this->getEnvironment()->getDataProvider();
            $dataProvider->saveEach($models);

            $this->triggerPostPasteModel($models);
            $this->clearModelCollection($models);
        }
    }