Updates a module with another revision in case their module versions differ.<p>

@param importFile the name of the import file

@throws Exception if something goes wrong
331721
public void updateModule(String importFile) throws Exception {

        CmsModule module = CmsModuleImportExportHandler.readModuleFromImport(importFile);
        String moduleName = module.getName();
        String moduleVersion = module.getVersionStr();
        m_shell.getOut().println("Updating module " + moduleName + " version " + moduleVersion);
        if (OpenCms.getModuleManager().getModule(moduleName) != null) {

            String oldVersion = OpenCms.getModuleManager().getModule(moduleName).getVersionStr();
            m_shell.getOut().println("Previous version '" + oldVersion + "' detected");
            if (!oldVersion.equals(moduleVersion)) {
                // the import version does not equal the present module version, replace the module
                OpenCms.getModuleManager().replaceModule(
                    m_cms,
                    importFile,
                    new CmsShellReport(m_cms.getRequestContext().getLocale()));
            }
        } else {
            importModule(importFile);
        }
    }
286076
private function loadImportUpdate($parentUpdate, ContextInterface $context)
    {
        if ($parentUpdate instanceof IsApplicableLayoutUpdateInterface && !$parentUpdate->isApplicable($context)) {
            return;
        }

        $imports = $parentUpdate->getImports();
        if (!is_array($imports)) {
            throw new LogicException(
                sprintf('Imports statement should be an array, %s given', gettype($imports))
            );
        }

        $importsReversed = array_reverse($imports);
        foreach ($importsReversed as $importData) {
            $import = $this->createImport($importData);
            if ($parentUpdate instanceof LayoutUpdateImportInterface) {
                $import->setParent($parentUpdate->getImport());
            }

            $files = $this->getImportResources($context->get(ThemeExtension::THEME_KEY), $import->getId());
            foreach ($files as $file) {
                $update = $this->loader->load($file);
                if ($update instanceof LayoutUpdateImportInterface) {
                    $update->setImport($import);
                    $update->setParentUpdate($parentUpdate);
                }

                $this->insertUpdate($parentUpdate, $update);

                $this->dependencyInitializer->initialize($update);

                if ($update instanceof ImportsAwareLayoutUpdateInterface) {
                    $this->loadImportUpdate($update, $context);
                }
            }
        }
    }
825103
public void actionUpdateLanguages() throws JspException {

        if ((m_paramSelectedLanguages != null) && !m_paramSelectedLanguages.isEmpty()) {
            try {
                CmsFile file = getCms().readFile(getParamTempfile(), CmsResourceFilter.IGNORE_EXPIRATION);
                CmsXmlContent content = CmsXmlContentFactory.unmarshal(getCms(), file);

                List<Locale> toLocales = new ArrayList<Locale>();
                for (Iterator<String> i = m_paramSelectedLanguages.iterator(); i.hasNext();) {
                    String language = i.next();
                    toLocales.add(CmsLocaleManager.getLocale(language));
                }

                // now transfer the contents
                transferContents(content, getElementLocale(), toLocales);

                // write the temporary file
                String decodedContent = content.toString();
                try {
                    file.setContents(decodedContent.getBytes(content.getEncoding()));
                } catch (UnsupportedEncodingException e) {
                    throw new CmsException(
                        Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()),
                        e);
                }
                // the file content might have been modified during the write operation
                CmsObject cloneCms = OpenCms.initCmsObject(getCms());
                CmsUUID tempProjectId = OpenCms.getWorkplaceManager().getTempFileProjectId();
                cloneCms.getRequestContext().setCurrentProject(getCms().readProject(tempProjectId));
                cloneCms.writeFile(file);

            } catch (Throwable e) {
                // show error dialog
                setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_UPDATE_LANGUAGES_0));
                includeErrorpage(this, e);
            }
        }
    }
1151818
private void updateExportParams() {

        m_exportParams.setExportAccountData(m_includeAccount.getValue().booleanValue());
        m_exportParams.setExportAsFiles(m_asFiles.getValue().booleanValue());
        m_exportParams.setExportProjectData(m_includeProject.getValue().booleanValue());
        m_exportParams.setExportResourceData(m_includeResource.getValue().booleanValue());
        m_exportParams.setInProject(m_modified.getValue().booleanValue());
        m_exportParams.setIncludeSystemFolder(m_includeSystem.getValue().booleanValue());
        m_exportParams.setIncludeUnchangedResources(m_includeUnchanged.getValue().booleanValue());
        String exportFileName = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
            OpenCms.getSystemInfo().getPackagesRfsPath() + File.separator + (String)m_target.getValue());
        m_exportParams.setPath(exportFileName);
        m_exportParams.setRecursive(m_recursive.getValue().booleanValue());
        m_exportParams.setResources(getResources());
        if (m_changedSince.getValue() != null) {
            m_exportParams.setContentAge(m_changedSince.getDate().getTime());
        } else {
            m_exportParams.setContentAge(0);
        }
    }
1295977
def update_version_module(check_name, old_ver, new_ver):
    
    version_file = get_version_file(check_name)
    contents = read_file(version_file)

    contents = contents.replace(old_ver, new_ver)
    write_file(version_file, contents)
375858
public final void setSourceFile(final String srcFile) {
        if (SwingUtilities.isEventDispatchThread()) {
            setSourceFileIntern(srcFile);
        } else {
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        setSourceFileIntern(srcFile);
                    }
                });
            } catch (final Exception ex) {
                ignore();
            }
        }
    }
1009593
public DynamicReportBuilder setTemplateFile(String path, boolean importFields, boolean importVariables, boolean importParameters, boolean importDatasets) {
        report.setTemplateFileName(path);
        report.setTemplateImportFields(importFields);
        report.setTemplateImportParameters(importParameters);
        report.setTemplateImportVariables(importVariables);
        report.setTemplateImportDatasets(importDatasets);
        return this;
    }
303603
protected void initModule() {

        Object o;
        CmsModule module;

        if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
            // this is the initial dialog call
            if (CmsStringUtil.isNotEmpty(m_paramModule)) {
                // edit an existing module, get it from manager
                o = OpenCms.getModuleManager().getModule(m_paramModule);
            } else {
                // create a new module
                o = null;
            }
        } else {
            // this is not the initial call, get module from session
            o = getDialogObject();
        }

        if (!(o instanceof CmsModule)) {
            // create a new module
            module = new CmsModule();

        } else {
            // reuse module stored in session
            module = (CmsModule)((CmsModule)o).clone();
        }

        List exportpoints = module.getExportPoints();
        m_exportpoint = new CmsExportPoint();
        if ((exportpoints != null) && (exportpoints.size() > 0)) {
            Iterator i = exportpoints.iterator();
            while (i.hasNext()) {
                CmsExportPoint exportpoint = (CmsExportPoint)i.next();
                if (exportpoint.getUri().equals(m_paramExportpoint)) {
                    m_exportpoint = exportpoint;
                }
            }
        }

    }
135590
public void setImportSite(String importSite) {

        checkFrozen();
        if (importSite != null) {
            importSite = importSite.trim();
        }
        m_site = importSite;
        m_hasImportSite = true;
    }
310862
private static void updateFile(CmsObject cms, CmsFile file, CmsMacroResolver macroResolver) throws CmsException {

        String encoding = cms.readPropertyObject(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true).getValue(
            OpenCms.getSystemInfo().getDefaultEncoding());
        String content;
        try {
            content = macroResolver.resolveMacros(new String(file.getContents(), encoding));
        } catch (UnsupportedEncodingException e) {
            try {
                content = macroResolver.resolveMacros(
                    new String(file.getContents(), Charset.defaultCharset().toString()));
            } catch (UnsupportedEncodingException e1) {
                content = macroResolver.resolveMacros(new String(file.getContents()));
            }
        }
        // update the content
        try {
            file.setContents(content.getBytes(encoding));
        } catch (UnsupportedEncodingException e) {
            try {
                file.setContents(content.getBytes(Charset.defaultCharset().toString()));
            } catch (UnsupportedEncodingException e1) {
                file.setContents(content.getBytes());
            }
        }
        // write the target file
        cms.writeFile(file);
    }
1101150
public void setScriptFile(final String scriptFile) {
        this.scriptFile = scriptFile;
        this.scriptType = determineScriptType(scriptFile);
        if (scriptType != SCRIPT_TYPE.CONTENTS) {
            // assume that if adjusting the file, engine name should also be re-calc'd
            // if scriptType is CONTENTS then we can't determine engineName anyway
            this.engineName = getScriptEngineName(scriptFile);
        }
    }
1264254
public void updateNewModuleSelector() {

        ComboBox newModuleSelector = createModuleSelector();
        ((AbstractLayout)(m_moduleSelector.getParent())).replaceComponent(m_moduleSelector, newModuleSelector);
        m_moduleSelector = newModuleSelector;
        m_moduleSelector.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 1L;

            public void valueChange(ValueChangeEvent event) {

                String moduleName = (String)(event.getProperty().getValue());
                addSelectableModule(moduleName);
                updateNewModuleSelector();
            }
        });
    }
615974
public void importModule() {

        Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide);
        CmsImportTabForm form = new CmsImportTabForm(m_app, this::reload);
        window.setContent(form);
        window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_MODULES_IMPORT_TITLE_0));
        A_CmsUI.get().addWindow(window);
        window.center();
    }
482978
public void addImportVersionClass(I_CmsImport importVersionClass) {

        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ADDED_IMPORT_VERSION_1, importVersionClass));
        }
        m_importVersionClasses.add(importVersionClass);
    }
546899
public void importResource() {

        m_resourceIdWasNull = false;

        try {
            if (m_throwable != null) {
                getReport().println(m_throwable);
                getReport().addError(m_throwable);

                CmsMessageContainer message = Messages.get().container(
                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), m_throwable);
                }
                m_throwable = null;
                m_importACEs = false;
                m_resource = null;

                return;
            }

            // apply name translation and import path
            String translatedName = getRequestContext().addSiteRoot(
                CmsStringUtil.joinPaths(m_parameters.getDestinationPath(), m_destination));

            boolean resourceImmutable = checkImmutable(translatedName);
            translatedName = getRequestContext().removeSiteRoot(translatedName);
            // if the resource is not immutable and not on the exclude list, import it
            if (!resourceImmutable) {
                // print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                getReport().print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));
                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

                boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL);

                byte[] content = null;
                // get the file content

                if (m_source != null) {
                    content = m_helper.getFileBytes(m_source);
                }
                int size = 0;
                if (content != null) {
                    size = content.length;
                }
                setDefaultsForEmptyResourceFields();
                // create a new CmsResource
                CmsResource resource = createResourceObjectFromFields(translatedName, size);

                if (m_resourceBuilder.getType().isFolder()
                    || m_resourceIdWasNull
                    || hasContentInVfsOrImport(resource)) {
                    // import this resource in the VFS
                    m_resource = getCms().importResource(
                        translatedName,
                        resource,
                        content,
                        new ArrayList<CmsProperty>(m_properties.values()));
                }

                if (m_resource != null) {
                    m_indexToStructureId.put(Integer.valueOf(m_fileCounter), m_resource.getStructureId());
                }

                // only set permissions if the resource did not exists or if the keep permissions flag is not set
                m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions());

                if (m_resource != null) {
                    getReport().println(
                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                        I_CmsReport.FORMAT_OK);

                    if (OpenCms.getResourceManager().getResourceType(
                        m_resource.getTypeId()) instanceof I_CmsLinkParseable) {
                        // store for later use
                        m_parseables.add(m_resource);
                    }
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_IMPORTING_4,
                                new Object[] {
                                    String.valueOf(m_fileCounter),
                                    String.valueOf(m_totalFiles),
                                    translatedName,
                                    m_destination}));
                    }
                } else {
                    // resource import failed, since no CmsResource was created
                    getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    getReport().println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(m_fileCounter),
                                String.valueOf(m_totalFiles),
                                translatedName));
                    }
                }
            } else {
                m_resource = null;
                // skip the file import, just print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                getReport().println(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));

                if (LOG.isInfoEnabled()) {
                    LOG.info(
                        Messages.get().getBundle().key(
                            Messages.LOG_SKIPPING_3,
                            String.valueOf(m_fileCounter),
                            String.valueOf(m_totalFiles),
                            translatedName));
                }
                // do not import ACEs
                m_importACEs = false;
            }
        } catch (Exception e) {
            m_resource = null;
            m_importACEs = false;

            getReport().println(e);
            getReport().addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            return;
        }
    }
1337383
protected void update(CmsUUID structureId, String rootPath, int type, CmsResourceState resState) {

        if (CmsResource.isTemporaryFileName(rootPath)) {
            return;
        }
        m_pathCache.replace(structureId, rootPath);
        if (isSitemapConfiguration(rootPath, type)) {
            m_workQueue.add(structureId);
        } else if (isModuleConfiguration(rootPath, type)) {
            LOG.info("Changed module configuration file " + rootPath + "(" + structureId + ")");
            m_workQueue.add(ID_UPDATE_MODULES);
        } else if (isElementView(type)) {
            m_workQueue.add(ID_UPDATE_ELEMENT_VIEWS);
        } else if (m_state.getFolderTypes().containsKey(rootPath)) {
            m_workQueue.add(ID_UPDATE_FOLDERTYPES);
        } else if (isMacroOrFlexFormatter(type, rootPath)) {
            try {
                String path = CmsResource.getParentFolder(CmsResource.getParentFolder(rootPath));
                path = CmsStringUtil.joinPaths(path, ".config");
                CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION;
                if (m_cms.existsResource(path, filter)) {

                    CmsResource config = m_cms.readResource(path, filter);
                    m_workQueue.add(config.getStructureId());
                }
            } catch (Exception e) {
                LOG.warn(e.getMessage(), e);
            }
        }
    }
1019174
public function checkModuleValidity(UploadedFile $file, ExecutionContextInterface $context)
    {
        $modulePath = $this->unzipModule($file);

        if ($modulePath !== false) {
            try {
                // get the first directory
                $moduleFiles = $this->getDirContents($modulePath);
                if (\count($moduleFiles['directories']) !== 1) {
                    throw new Exception(
                        Translator::getInstance()->trans(
                            "Your zip must contain 1 root directory which is the root folder directory of your module"
                        )
                    );
                }

                $moduleDirectory = $moduleFiles['directories'][0];

                $this->modulePath = sprintf('%s/%s', $modulePath, $moduleDirectory);

                $moduleValidator = new ModuleValidator($this->modulePath);

                $moduleValidator->validate();

                $this->moduleDefinition = $moduleValidator->getModuleDefinition();
            } catch (Exception $ex) {
                $context->addViolation(
                    Translator::getInstance()->trans(
                        "The module is not valid : %message",
                        ['%message' => $ex->getMessage()]
                    )
                );
            }
        }
    }