Import definitions from file

@param array $overrideData The overridden data
@throws \Exception
437595
private function importDefinitionsFromFile(array $overrideData): array
    {
        if (!file_exists($this->file)) {
            throw new \Exception('File not found: ' . $this->file);
        }

        // Load data from yam file and replace with override data;
        $definitions = Data::parseYamlFile($this->file);
        return array_replace_recursive($definitions, $overrideData);
    }
239769
public function import(array $data): void
    {
        if(!$this->isDataSetProperly($data)) {
            return;
        }

        $wakeup = function (array $array): EncapsulatedEdge {
            return EncapsulatedEdge::fromArray($array);
        };

        $this->out = array_map($wakeup, $data["out"]); 
        $this->in = array_map($wakeup, $data["in"]); 
        foreach($data["from"] as $from => $frozen) {
            $this->from[$from] = array_map($wakeup, $frozen); 
        }
        foreach($data["to"] as $to => $frozen) {
            $this->to[$to] = array_map($wakeup, $frozen); 
        }
    }
592758
public function append($append = [], $override = false)
    {
        $this->each(function ($model) use ($append, $override) {
            /** @var Model $model */
            $model && $model->append($append, $override);
        });

        return $this;
    }
34041
private function import(&$data)
    {
        $imports = array();
        preg_match_all('/#@([-a-z0-9\/_]+)\\n/is', $data, $imports, PREG_SET_ORDER);
        foreach ($imports as $import) {
            $importPath = FS2LANG . '/' . $this->local . '/' . $import[1] . '.txt';
            $importData = @file_get_contents($importPath);

            // getting file content ok
            if ($importData != false) {
                $importData = str_replace(array("\r\n", "\r"), "\n", $importData); // unify linebreaks
                $this->import($importData);
                $replace = '/#@' . preg_quote($import[1], '/') . '/i';
                $data = preg_replace($replace, $importData, $data);
                // replace all imports recursive
            }
        }
        unset($imports);
    }
186848
public function update($data, $override = null)
    {
        if (func_num_args() == 2) {
            $override['id'] = $data;
            $data = $override;
        }

        $response = $this->ontraport->put(
            $this->getNamespace(), $this->toArray($data)
        );

        return $this->ontraport->item($this, $response);
    }
878648
public function importarRutas(array $rutas)
    {
        foreach ($rutas as $ruta) {
            if (isset($ruta[4])) {
                $this->agregarRuta($ruta[0], $ruta[1], $ruta[2], $ruta[3], $ruta[4]);
            } elseif (isset($ruta[3])) {
                $this->agregarRuta($ruta[0], $ruta[1], $ruta[2], $ruta[3]);
            } elseif (is_int($ruta[0])) {
                $this->agregarRutaEstadoHttp($ruta[0], $ruta[1]);
            } else {
                $this->agregarRuta($ruta[0], $ruta[1], $ruta[2]);
            }
        }
    }
938701
private function loadFromFile($filename, $overwrite = false)
    {
        try {
            $yamlDatas = Yaml::parse(file_get_contents($filename));

            if (is_array($yamlDatas)) {
                if (true === $this->debug) {
                    $this->debug_data[$filename] = $yamlDatas;
                }

                if (self::CONFIG_FILE.'.'.self::EXTENSION === basename($filename) ||
                    self::CONFIG_FILE.'.'.$this->environment.'.'.self::EXTENSION === basename($filename)) {
                    foreach ($yamlDatas as $component => $config) {
                        if (!is_array($config)) {
                            $this->container->get('logger')->error('Bad configuration, array expected, given : '.$config);
                        }
                        $this->setSection($component, $config, $overwrite);
                    }
                } else {
                    $this->setSection(basename($filename, '.'.self::EXTENSION), $yamlDatas, $overwrite);
                }
            }
        } catch (ParseException $e) {
            throw new InvalidConfigException($e->getMessage(), null, $e, $e->getParsedFile(), $e->getParsedLine());
        }
    }
998146
private function overrideConfiguration(array $configuration, array $override)
    {
        $configuration['parameters'] = array_replace(
            $configuration['parameters'],
            $override['parameters']
        );

        unset($override['parameters']);

        return array_replace($configuration, $override);
    }
835415
protected function process_assign_override($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;

        // Based on userinfo, we'll restore user overides or no.
        $userinfo = $this->get_setting_value('userinfo');

        // Skip user overrides if we are not restoring userinfo.
        if (!$userinfo && !is_null($data->userid)) {
            return;
        }

        // Skip group overrides if we are not restoring groupinfo.
        $groupinfo = $this->get_setting_value('groups');
        if (!$groupinfo && !is_null($data->groupid)) {
            return;
        }

        $data->assignid = $this->get_new_parentid('assign');

        if (!is_null($data->userid)) {
            $data->userid = $this->get_mappingid('user', $data->userid);
        }
        if (!is_null($data->groupid)) {
            $data->groupid = $this->get_mappingid('group', $data->groupid);
        }

        $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate);
        $data->duedate = $this->apply_date_offset($data->duedate);
        $data->cutoffdate = $this->apply_date_offset($data->cutoffdate);

        $newitemid = $DB->insert_record('assign_overrides', $data);

        // Add mapping, restore of logs needs it.
        $this->set_mapping('assign_override', $oldid, $newitemid);
    }
1338469
protected function _importData()
    {
        if (Import::BEHAVIOR_DELETE == $this->getBehavior()) {
            $this->deleteCategories();
        } else {
            $this->saveCategories();
            $this->saveOnTab();
        }

        //$this->reindexImportedCategories();

        $this->eventManager->dispatch('catalog_category_import_finish_before', ['adapter' => $this]);

        return true;
    }
756145
public static function import(array $responseData)
    {
        $response = new self(
            $responseData['statusCode'],
            $responseData['responseHeaders']['Content-Type']
        );
        unset($responseData['responseHeaders']['Content-Type']);
        foreach ($responseData['responseHeaders'] as $key => $value) {
            $response->addHeader($key, $value);
        }
        $response->setBody($responseData['responseBody']);

        return $response;
    }
509776
final function import($data)
    {
        if ($data === null)
            return $this;

        if (!(is_array($data) || $data instanceof \Traversable || $data instanceof \stdClass))
            throw new \InvalidArgumentException(sprintf(
                'Data must be instance of \Traversable, \stdClass or array. given: (%s) on (%s).'
                , \Poirot\Std\flatten($data), get_class($this)
            ));

        if ($data instanceof \stdClass)
            $data = \Poirot\Std\toArrayObject($data);

        $this->doSetFrom($data);

        return $this;
    }
843369
public function importDataV1x(array $data)
    {
        $this->_packageXml = null;
        $this->_init();
        // Import simple data
        if (isset($data['name'])) {
            $this->setName($data['name']);
        }
        if (isset($data['summary'])) {
            $this->setSummary($data['summary']);
        }
        if (isset($data['description'])) {
            $this->setDescription($data['description']);
        }
        if (isset($data['channel'])) {
            $this->setChannel($this->convertChannelFromV1x($data['channel']));
        }
        if (isset($data['license'])) {
            if (is_array($data['license'])) {
                $this->setLicense($data['license']['_content'], $data['license']['attribs']['uri']);
            } else {
                $this->setLicense($data['license']);
            }
        }
        if (isset($data['version'])) {
            $this->setVersion($data['version']['release']);
        }
        if (isset($data['stability'])) {
            $this->setStability($data['stability']['release']);
        }
        if (isset($data['notes'])) {
            $this->setNotes($data['notes']);
        }
        if (isset($data['date'])) {
            $this->setDate($data['date']);
        }
        if (isset($data['time'])) {
            $this->setTime($data['time']);
        }

        // Import authors
        $authors = array();
        $authorRoles = array('lead', 'developer', 'contributor', 'helper');
        foreach ($authorRoles as $authorRole) {
            if (isset($data[$authorRole])) {
                $authorList = $data[$authorRole];
                if (!is_array($authorList) || isset($authorList['name'])) {
                    $authorList = array($authorList);
                }
                foreach ($authorList as $authorRawData) {
                    $author = array();
                    $author['name'] = $authorRawData['name'];
                    $author['user'] = $authorRawData['user'];
                    $author['email'] = $authorRawData['email'];
                    array_push($authors, $author);
                }
            }
        }
        $this->setAuthors($authors);

        // Import dependencies
        $packages = array();
        $extensions = array();
        if (isset($data['dependencies']) && is_array($data['dependencies'])) {
            $dependencySections = array('required', 'optional');
            $elementTypes = array('package', 'extension');
            foreach ($dependencySections as $dependencySection) {
                if (isset($data['dependencies'][$dependencySection])) {
                    // Handle required PHP version
                    if ($dependencySection == 'required' && isset($data['dependencies']['required']['php'])) {
                        $this->setDependencyPhpVersion($data['dependencies']['required']['php']['min'], $data['dependencies']['required']['php']['max']);
                    }
                    // Handle extensions
                    if (isset($data['dependencies'][$dependencySection]['extension'])) {
                        $extensionList = $data['dependencies'][$dependencySection]['extension'];
                        if (!is_array($extensionList) || isset($extensionList['name'])) {
                            $extensionList = array($extensionList);
                        }
                        foreach ($extensionList as $extensionRawData) {
                            $extension = array();
                            $extension['name'] = $extensionRawData['name'];
                            $extension['min_version'] = isset($extensionRawData['min']) ? $extensionRawData['min'] : null;
                            $extension['max_version'] = isset($extensionRawData['max']) ? $extensionRawData['max'] : null;
                            array_push($extensions, $extension);
                        }
                    }
                    // Handle packages
                    if (isset($data['dependencies'][$dependencySection]['package'])) {
                        $packageList = $data['dependencies'][$dependencySection]['package'];
                        if (!is_array($packageList) || isset($packageList['name'])) {
                            $packageList = array($packageList);
                        }
                        foreach ($packageList as $packageRawData) {
                            $package = array();
                            $package['name'] = $packageRawData['name'];
                            $package['channel'] = $this->convertChannelFromV1x($packageRawData['channel']);
                            $package['min_version'] = isset($packageRawData['min']) ? $packageRawData['min'] : null;
                            $package['max_version'] = isset($packageRawData['max']) ? $packageRawData['max'] : null;
                            array_push($packages, $package);
                        }
                    }
                }
            }
        }
        $this->setDependencyPackages($packages);
        $this->setDependencyPhpExtensions($extensions);

        // Import contents
        if (isset($data['contents']) && is_array($data['contents']) && is_array($data['contents']['dir'])) {
            // Handle files
            $root = $data['contents']['dir'];
            if (isset($data['contents']['dir']['file'])) {
                $fileList = $data['contents']['dir']['file'];
                if (!is_array($fileList) || isset($fileList['attribs'])) {
                    $fileList = array($fileList);
                }
                foreach ($fileList as $fileRawData) {
                    $targetName = $fileRawData['attribs']['role'];
                    $parentTargetNode = $this->_getNode('target', $this->_packageXml->contents, $targetName);
                    $filePath = $fileRawData['attribs']['name'];
                    $filePathParts = explode('/', $filePath);
                    $fileName = array_pop($filePathParts);
                    $parentDirNode = null;
                    if (!empty($filePathParts)) {
                        $parentDirNode = $parentTargetNode;
                        foreach ($filePathParts as $directoryName) {
                            $parentDirNode = $this->_getNode('dir', $parentDirNode, $directoryName);
                        }
                    } else {
                        $parentDirNode = $this->_getNode('dir', $parentTargetNode, '.');
                    }
                    $fileNode = $parentDirNode->addChild('file');
                    $fileNode->addAttribute('name', $fileName);
                    $fileNode->addAttribute('hash', $fileRawData['attribs']['md5sum']);
                }
            }
        }

        return $this;
    }
46630
public function importFromLocal($overwrite = true, $delete = false) {
        $path = $this->_data;
        $file = new File($path);
        $target = $this->findDestination($file, $overwrite);

        if (copy($path, $target)) {
            if ($delete) {
                $file->delete();
            }

            $this->_file = new File($target);

            return true;
        }

        throw new IoException(sprintf('Failed to copy %s to new location', $file->basename()));
    }
46849
public function importData($data)
    {
        foreach ($data as $key => $row) {
            if ($row) {
                try {
                    $success = $this->importOne($row);
                    $errorMessage = '';
                } catch (Exception $e) {
                    $success = false;
                    $errorMessage = $e->getMessage();
                }

                $this->statistics[$key] = ['r' => $success, 'm' => $errorMessage];
            }
        }

        $this->afterImport($data);
    }
64665
protected function setTemplateData(array $overrides = [])
    {
        if (empty($overrides['template_data'])) {
            $this->templateData = [];
        } else {
            $this->templateData = $overrides['template_data'];
            $overrides = array_diff_key($overrides, ['template_data' => []]);
        }

        return $overrides;
    }
884052
public function importFromStream($overwrite = true) {
        $target = $this->findDestination($this->_data, $overwrite);
        $input = fopen('php://input', 'r');
        $output = fopen($target, 'w');

        $size = stream_copy_to_stream($input, $output);

        fclose($input);
        fclose($output);

        if ($size <= 0) {
            @unlink($target);

            throw new IoException('No file detected in input stream');
        }

        $this->_file = new File($target);

        return $size;
    }