Action to migrate a selected object through to SS

@param array $request
355535
public function migrate($request) {
		$migrationTarget 		= isset($request['MigrationTarget']) ? $request['MigrationTarget'] : '';
		$fileMigrationTarget 	= isset($request['FileMigrationTarget']) ? $request['FileMigrationTarget'] : '';
		$includeSelected 		= isset($request['IncludeSelected']) ? $request['IncludeSelected'] : 0;
		$includeChildren 		= isset($request['IncludeChildren']) ? $request['IncludeChildren'] : 0;
		$duplicates 			= isset($request['DuplicateMethod']) ? $request['DuplicateMethod'] : ExternalContentTransformer::DS_OVERWRITE;
		$selected 				= isset($request['ID']) ? $request['ID'] : 0;

		if(!$selected){
			$messageType = 'bad';
			$message = _t('ExternalContent.NOITEMSELECTED', 'No item selected to import.');
		}

		if(!$migrationTarget || !$fileMigrationTarget){
			$messageType = 'bad';
			$message = _t('ExternalContent.NOTARGETSELECTED', 'No target to import to selected.');
		}

		if ($selected && ($migrationTarget || $fileMigrationTarget)) {
			// get objects and start stuff
			$target = null;
			$targetType = 'SiteTree';
			if ($migrationTarget) {
				$target = DataObject::get_by_id('SiteTree', $migrationTarget);
			} else {
				$targetType = 'File';
				$target = DataObject::get_by_id('File', $fileMigrationTarget);
			}

			$from = ExternalContent::getDataObjectFor($selected);
			if ($from instanceof ExternalContentSource) {
				$selected = false;
			}

			if (isset($request['Repeat']) && $request['Repeat'] > 0) {
				$job = new ScheduledExternalImportJob($request['Repeat'], $from, $target, $includeSelected, $includeChildren, $targetType, $duplicates, $request);
				singleton('QueuedJobService')->queueJob($job);

				$messageType = 'good';
				$message = _t('ExternalContent.CONTENTMIGRATEQUEUED', 'Import job queued.');
			} else {
				$importer = $from->getContentImporter($targetType);
				if ($importer) {
					$result = $importer->import($from, $target, $includeSelected, $includeChildren, $duplicates, $request);

					$messageType = 'good';
					if ($result instanceof QueuedExternalContentImporter) {
						$message = _t('ExternalContent.CONTENTMIGRATEQUEUED', 'Import job queued.');
					} else {
						$message = _t('ExternalContent.CONTENTMIGRATED', 'Import Successful.');
					}
				}
			}
		}

		Session::set("FormInfo.Form_EditForm.formError.message",$message);
		Session::set("FormInfo.Form_EditForm.formError.type", $messageType);

		return $this->getResponseNegotiator()->respond($this->request);
	}
441473
public function moveUpAction(Request $request)
    {
        $block = $this->findBlockByRequest($request);
        $row = $block->getRow();

        $removedId = $this->getViewBuilder()->buildBlock($block)->getAttributes()->getId();

        try {
            $sibling = $this->getEditor()->getBlockManager()->moveUp($block);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($row);
        $this->validate($sibling);
        $this->persist($row);
        $this->persist($sibling);

        $createdId = $this->getViewBuilder()->buildBlock($block)->getAttributes()->getId();

        $data = [
            'removed' => [$removedId],
            'created' => $createdId,
            'rows'    => [
                $this->getViewBuilder()->buildRow($row),
                $this->getViewBuilder()->buildRow($sibling),
            ],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
159155
public function move($id, Request $request)
    {
        $this->validate($request, ['category_id' => ['required']]);

        $thread = $this->model()->find($id);

        $category = Category::find($request->input('category_id'));

        if (!$category->threadsEnabled) {
            return $this->buildFailedValidationResponse($request, trans('forum::validation.category_threads_enabled'));
        }

        return $this->updateModel($thread, ['category_id' => $category->id], ['moveThreadsTo', $category]);
    }
41368
private function _convertGetServiceStatus($request) {

        $parameters = array();
        $parameters['Action'] = 'GetServiceStatus';
        if ($request->isSetSellerId()) {
            $parameters['SellerId'] =  $request->getSellerId();
        }
        if ($request->isSetMWSAuthToken()) {
            $parameters['MWSAuthToken'] =  $request->getMWSAuthToken();
        }

        return $parameters;
    }
836068
public function moveUpAction(Request $request)
    {
        $context = $this->loadContext($request);

        $resource = $context->getResource();

        $this->isGranted('EDIT', $resource);

        $repo = $this->getRepository();
        $repo->moveUp($resource, 1);

        return $this->redirectToReferer($this->generateUrl(
            $this->config->getRoute('list'),
            $context->getIdentifiers()
        ));
    }
1187127
public static function clean($request = null)
    {
        switch ($request) {
            case 'post':
                unset($_POST);
            break;

            case 'get':
                unset($_GET);
            break;

            case 'any':
                unset($_REQUEST);
            break;

            default:
                unset($_POST);
                unset($_REQUEST);
                unset($_GET);
        }
    }
1024166
function handleActionOrID($request)
    {
        if (is_numeric($request->param('Action'))) {
            $controller = $this->config()->recordController;
            return new $controller($this, $this->getRecordType(), $request);
        } else {
            return $this->handleAction($request, null);
        }
    }
740911
public function import(SS_HTTPRequest $request)
    {
        $hasheader = (bool)$request->postVar('HasHeader');
        $cleardata = $this->component->getCanClearData() ?
                         (bool)$request->postVar('ClearData') :
                         false;
        if ($request->postVar('action_import')) {
            $file = File::get()
                ->byID($request->param('FileID'));
            if (!$file) {
                return "file not found";
            }
            $colmap = Convert::raw2sql($request->postVar('mappings'));
            if ($colmap) {
                //save mapping to cache
                $this->cacheMapping($colmap);
                //do import
                $results = $this->importFile(
                    $file->getFullPath(),
                    $colmap,
                    $hasheader,
                    $cleardata
                );
                $this->gridField->getForm()
                    ->sessionMessage($results->getMessage(), 'good');
            }
        }
        $controller = $this->getToplevelController();
        $controller->redirectBack();
    }
1105597
public function add($request)
    {
        $this->onBefore($request);
        array_push($this->_requests, $request);
        curl_multi_add_handle($this->_mh, $request->curl);
        $this->_updated = true;
    }
695160
public function handleNew(array $request = [])
    {
        if (isset($request['class']) === true && $request['class'] === '') {
            unset($request['class']);
        }
        if (isset($request['type']) === true && $request['type'] === '') {
            unset($request['type']);
        }
        if (isset($request['navigation_block']) === true && $request['navigation_block'] === '') {
            unset($request['navigation_block']);
        }
        if (isset($request['navigation_id']) === true && $request['navigation_id'] === '') {
            unset($request['navigation_id']);
        }
        $validator = new \Valitron\Validator($request);
        $validator->rule(function ($field, $value, $params, $fields) {
            if ((empty($value) === true && empty($fields['link']) === true)
                || (empty($value) === false && empty($fields['link']) === false)) {
                return false;
            } elseif (empty($value) === false) {
                $page = Model\Page::find($value);
                if ($page === null) {
                    return false;
                }
            }
            return true;
        }, "page_id")->message("{field} is required, must be unique, without a link");
        $validator->rule(function ($field, $value, $params, $fields) {
            if ((empty($value) === true && empty($fields['page_id']) === true)
                || (empty($value) === false && empty($fields['page_id']) === false)) {
                return false;
            }
            return file_exists(rtrim(public_path(), '/') . $value) || (filter_var($value, FILTER_VALIDATE_URL) !== false);
        }, "link")->message("{field} is requried without a page ID");
        $validator->rule('required', ['title']);
        $validator->rule('optional', ['class', 'type', 'navigation_block', 'navigation_id']);
        $validator->rule('numeric', ['type', 'navigation_block']);
        $validator->rule(function ($field, $value, $params, $fields) {
            if (is_array($value) === true || preg_match('/\w+(,\s?\w+)*/', $value) === 1) {
                return true;
            }
            return false;
        }, "class")->message("{field} must be an array or comma-separated");
        $validator->rule(function ($field, $value, $params, $fields) {
            $navigation = Model\Navigation::find($value);
            if ($navigation === null) {
                return false;
            }
            return true;
        }, "navigation_id")->message("{field} must be child of a valid navigation link");
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            $navigations_list = $this->core->api('Navigation/all/flatten', 'GET')->run();
            $pages = $this->core->api('Page/all', 'GET')->run();
            $pages_list = [];
            foreach ($pages['response'] as $key => $page) {
                if ($page->status === true) {
                    $pages_list[] = $page;
                }
            }
            return $this->templates->render("Main::Navigation", [
                "messages" => [
                    'error' => $validator->errors(),
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "navigations" => $navigations_list['response'],
                "pages" => $pages_list
            ]);
        }

        $response = $this->core->api('Navigation', 'POST')->run($request);

        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            $navigations_list = $this->core->api('Navigation/all/flatten', 'GET')->run();
            $pages = $this->core->api('Page/all', 'GET')->run();
            $pages_list = [];
            foreach ($pages['response'] as $key => $page) {
                if ($page->status === true) {
                    $pages_list[] = $page;
                }
            }
            return $this->templates->render("Main::Navigation", [
                "messages" => [
                    'error' => $response['response'],
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "navigations" => $navigations_list['response'],
                "pages" => $pages_list
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('navigations-page') . "?m=2");
            } else {
                return 'Redirect: ' . $this->router->generate('navigations-page') . "?m=2";
            }
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }
731540
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $details = ArrayObject::ensureArrayObject($request->getModel());

        $details->replace($this->api->getTransactionData((array) $details));
    }
582480
public function copyAction(Request $request)
    {
        $parentId = $request->get('id');
        $sourceId = $request->get('for_tree_id');
        $prevId = $request->get('prev_id');

        $elementService = $this->get('phlexible_element.element_service');
        $treeManager = $this->get('phlexible_tree.tree_manager');

        $sourceTree = $treeManager->getByNodeId($sourceId);
        $sourceNode = $sourceTree->get($sourceId);

        $targetTree = $treeManager->getByNodeId($parentId);
        $parentNode = $targetTree->get($parentId);
        $prevNode = $targetTree->get($prevId);

        $sourceElement = $elementService->findElement($sourceNode->getTypeId());
        $sourceElementVersion = $elementService->findLatestElementVersion($sourceElement);
        $sourceStructure = $elementService->findElementStructure($sourceElementVersion);

        $targetElement = $elementService->createElement(
            $sourceElementVersion->getElementSource(),
            $sourceElement->getMasterLanguage(),
            $this->getUser()->getId()
        );

        // place new element in element_tree
        $targetNode = $targetTree->create(
            $parentNode,
            $prevNode,
            $sourceNode->getType(),
            $targetElement->getEid(),
            $sourceNode->getAttributes(),
            $this->getUser()->getId(),
            $sourceNode->getSortMode(),
            $sourceNode->getSortDir(),
            $sourceNode->getInNavigation()
        );

        $targetStructure = clone $sourceStructure;
        $targetStructure->setId(null);
        $targetStructure->setDataId(UuidUtil::generate());

        $rii = new \RecursiveIteratorIterator(new ElementStructureIterator($targetStructure->getStructures()), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $structure) {
            $structure->setId(null);
            $structure->setDataId(UuidUtil::generate());
        }

        $targetElementVersion = $elementService->createElementVersion(
            $targetElement,
            $targetStructure,
            null,
            $this->getUser()->getId()
        );

        return new ResultResponse(true, 'Element copied.', ['id' => $targetNode->getId()]);
    }
1318760
protected function inExceptArray($request)
  {
    foreach ($this->except as $except) {
      if ($request->is($except)) {
        return true;
      }
    }

    return false;
  }
1284036
public function handleHttpRequest($request)
    {
        $this->parseRequestBase($request);

        if (isset($request->header['x-rpc']) && $request->header['x-rpc'] == 1) {
            $this->routeParams->isRpc          = true;
            $this->routeParams->params         = $request->post ?? $request->get ?? [];
            $this->routeParams->controllerName = 'Rpc';
            $this->routeParams->methodName     = 'Index';
            $this->controllerClassName         = '\PG\MSF\Controllers\Rpc';
            $this->routeParams->path           = '/Rpc/Index';
        } else {
            if ($this->routeParams->path) {
                $this->parsePath($this->routeParams->path);
            }
        }
    }
363646
public function run($request)
    {
        // Loading packages and all their updates can be quite memory intensive.
        $memoryLimit = $this->config()->get('memory_limit');
        if ($memoryLimit) {
            if (Environment::getMemoryLimitMax() < Convert::memstring2bytes($memoryLimit)) {
                Environment::setMemoryLimitMax($memoryLimit);
            }
            Environment::increaseMemoryLimitTo($memoryLimit);
        }

        $composerLock = $this->getComposerLoader()->getLock();
        $rawPackages = array_merge($composerLock->packages, (array) $composerLock->{'packages-dev'});
        $packages = $this->getPackageInfo($rawPackages);

        // Get "name" from $packages and put into an array
        $moduleNames = array_column($packages, 'Name');

        $supportedPackages = $this->getSupportedPackages();
        $moduleHealthInfo = $this->getHealthIndicator($moduleNames);

        // Extensions to the process that add data may rely on external services.
        // There may be a communication issue between the site and the external service,
        // so if there are 'none' we should assume this is untrue and _not_ proceed
        // to remove everything. Stale information is better than no information.
        if ($packages) {
            // There is no onBeforeDelete for Package
            $table = DataObjectSchema::create()->tableName(Package::class);
            SQLDelete::create("\"$table\"")->execute();
            foreach ($packages as $package) {
                $packageName = $package['Name'];
                if (is_array($supportedPackages)) {
                    $package['Supported'] = in_array($packageName, $supportedPackages);
                }
                if (is_array($moduleHealthInfo) && isset($moduleHealthInfo[$packageName])) {
                    $package['Rating'] = $moduleHealthInfo[$packageName];
                }
                Package::create()->update($package)->write();
            }
        }
    }
290977
public function moveSnippet(SS_HTTPRequest $request) {
        $snippet=Snippet::get()->byID(intval($request->getVar('ID')));
        
        if(empty($snippet) || $snippet===false || $snippet->ID==0) {
            $this->response->setStatusCode(403, _t('CodeBank.SNIPPIT_NOT_EXIST', '_Snippit does not exist'));
            return;
        }
        
        $parentID=$request->getVar('ParentID');
        if(strpos($parentID, 'language-')!==false) {
            $lang=SnippetLanguage::get()->byID(intval(str_replace('language-', '', $parentID)));
            if(empty($lang) || $lang===false || $lang->ID==0) {
                $this->response->setStatusCode(403, _t('CodeBank.LANGUAGE_NOT_EXIST', '_Language does not exist'));
                return;
            }
            
            
            if($lang->ID!=$snippet->LanguageID) {
                $this->response->setStatusCode(403, _t('CodeBank.CANNOT_MOVE_TO_LANGUAGE', '_You cannot move a snippet to another language'));
                return;
            }
            
            //Move out of folder
            DB::query('UPDATE "Snippet" SET "FolderID"=0 WHERE "ID"='.$snippet->ID);
            
            
            $this->response->addHeader('X-Status', rawurlencode(_t('CodeBank.SNIPPET_MOVED', '_Snippet moved successfully')));
            return;
        }else if(strpos($parentID, 'folder-')!==false) {
            $folder=SnippetFolder::get()->byID(intval(str_replace('folder-', '', $parentID)));
            if(empty($folder) || $folder===false || $folder->ID==0) {
                $this->response->setStatusCode(403, _t('CodeBank.FOLDER_NOT_EXIST', '_Folder does not exist'));
                return;
            }
            
            
            if($folder->LanguageID!=$snippet->LanguageID) {
                $this->response->setStatusCode(403, _t('CodeBank.CANNOT_MOVE_TO_FOLDER', '_You cannot move a snippet to a folder in another language'));
                return;
            }
            
            //Move to folder
            DB::query('UPDATE "Snippet" SET "FolderID"='.$folder->ID.' WHERE "ID"='.$snippet->ID);
            
            
            $this->response->addHeader('X-Status', rawurlencode(_t('CodeBank.SNIPPET_MOVED', '_Snippet moved successfully')));
            return;
        }
        
        $this->response->setStatusCode(403, _t('CodeBank.UNKNOWN_PARENT', '_Unknown Parent'));
    }
277690
public function HandleRequest($request)
    {
        if ($this->typesInfos()->contains('image')) {
            $name = $this->type->search('image');
            if ($request[$name]) {
                $image = $this->upload($request[$name]);
                $request[$name] = $image;
            }
        }

        if ($this->typesInfos()->contains('select_multiple')) {
            $name = $this->type->search('select_multiple');
            if ($request[$name]) {
                $request[$name] = json_encode($request[$name]);
            }
        }
        return $request;
    }