use of org.craftercms.studio.api.v2.exception.UpgradeException in project studio by craftercms.
the class DbVersionUpgradeOperation method execute.
@Override
public void execute(final String site) throws UpgradeException {
try (Connection connection = getConnection();
PreparedStatement statement = connection.prepareStatement(sqlCommand)) {
statement.setString(1, nextVersion);
int updated = statement.executeUpdate();
connection.commit();
if (updated != 1) {
throw new UpgradeException("Error updating the db version");
}
logger.info("Database version updated to {0}", nextVersion);
} catch (SQLException e) {
throw new UpgradeException("Error updating the db version", e);
}
}
use of org.craftercms.studio.api.v2.exception.UpgradeException in project studio by craftercms.
the class BlueprintsUpgradeOperation method execute.
@Override
public void execute(final String site) throws UpgradeException {
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, site);
generalLockService.lock(gitLockKey);
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
Path globalConfigPath = helper.buildRepoPath(GitRepositories.GLOBAL);
Path blueprintsPath = Paths.get(globalConfigPath.toAbsolutePath().toString(), studioConfiguration.getProperty(BLUE_PRINTS_PATH));
String studioManifestLocation = servletContext.getRealPath(STUDIO_MANIFEST_LOCATION);
String blueprintsManifestLocation = Paths.get(blueprintsPath.toAbsolutePath().toString(), "BLUEPRINTS.MF").toAbsolutePath().toString();
boolean blueprintManifestExists = Files.exists(Paths.get(blueprintsManifestLocation));
InputStream studioManifestStream = FileUtils.openInputStream(new File(studioManifestLocation));
Manifest studioManifest = new Manifest(studioManifestStream);
VersionInfo studioVersion = VersionInfo.getVersion(studioManifest);
InputStream blueprintsManifestStream = null;
Manifest blueprintsManifest = null;
VersionInfo blueprintsVersion = null;
if (blueprintManifestExists) {
blueprintsManifestStream = FileUtils.openInputStream(new File(blueprintsManifestLocation));
blueprintsManifest = new Manifest(blueprintsManifestStream);
blueprintsVersion = VersionInfo.getVersion(blueprintsManifest);
}
if (!blueprintManifestExists || !StringUtils.equals(studioVersion.getPackageBuild(), blueprintsVersion.getPackageBuild()) || (StringUtils.equals(studioVersion.getPackageBuild(), blueprintsVersion.getPackageBuild()) && !StringUtils.equals(studioVersion.getPackageBuildDate(), blueprintsVersion.getPackageBuildDate()))) {
String bootstrapBlueprintsFolderPath = servletContext.getRealPath(FILE_SEPARATOR + BOOTSTRAP_REPO_PATH + FILE_SEPARATOR + BOOTSTRAP_REPO_GLOBAL_PATH + FILE_SEPARATOR + studioConfiguration.getProperty(BLUE_PRINTS_PATH));
File bootstrapBlueprintsFolder = new File(bootstrapBlueprintsFolderPath);
File[] blueprintFolders = bootstrapBlueprintsFolder.listFiles(File::isDirectory);
for (File blueprintFolder : blueprintFolders) {
String blueprintName = blueprintFolder.getName();
FileUtils.deleteDirectory(Paths.get(blueprintsPath.toAbsolutePath().toString(), blueprintName).toFile());
TreeCopier tc = new TreeCopier(Paths.get(blueprintFolder.getAbsolutePath()), Paths.get(blueprintsPath.toAbsolutePath().toString(), blueprintName));
EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(Paths.get(blueprintFolder.getAbsolutePath()), opts, Integer.MAX_VALUE, tc);
}
FileUtils.copyFile(Paths.get(studioManifestLocation).toFile(), Paths.get(globalConfigPath.toAbsolutePath().toString(), studioConfiguration.getProperty(BLUE_PRINTS_PATH), "BLUEPRINTS.MF").toFile());
}
Repository globalRepo = helper.getRepository(site, GitRepositories.GLOBAL);
try (Git git = new Git(globalRepo)) {
StatusCommand statusCommand = git.status();
Status status = retryingRepositoryOperationFacade.call(statusCommand);
if (status.hasUncommittedChanges() || !status.isClean()) {
// Commit everything
// TODO: Consider what to do with the commitId in the future
AddCommand addCommand = git.add().addFilepattern(GIT_COMMIT_ALL_ITEMS);
retryingRepositoryOperationFacade.call(addCommand);
CommitCommand commitCommand = git.commit().setAll(true).setMessage(studioConfiguration.getProperty(REPO_BLUEPRINTS_UPDATED_COMMIT_MESSAGE));
retryingRepositoryOperationFacade.call(commitCommand);
}
} catch (GitAPIException err) {
logger.error("error creating initial commit for global configuration", err);
}
} catch (Exception e) {
throw new UpgradeException("Error upgrading blueprints in the global repo", e);
} finally {
generalLockService.unlock(gitLockKey);
}
}
use of org.craftercms.studio.api.v2.exception.UpgradeException in project studio by craftercms.
the class GlobalRepoUpgradeOperation method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(final String site) throws UpgradeException {
logger.debug("Upgrading global repo files");
clusterGlobalRepoSyncTask.execute();
for (Map.Entry<Resource, String> entry : files.entrySet()) {
if (overwrite || !contentRepository.contentExists(site, entry.getValue())) {
logger.debug("Upgrading global repo file: {0}", entry.getValue());
try (InputStream is = entry.getKey().getInputStream()) {
writeToRepo(site, entry.getValue(), is);
} catch (IOException e) {
throw new UpgradeException("Error while upgrading global repo file " + entry.getValue(), e);
}
} else {
logger.debug("File {0} already exists in global repo, it will not be changed", entry.getValue());
}
}
}
use of org.craftercms.studio.api.v2.exception.UpgradeException in project studio by craftercms.
the class AbstractPluginDescriptorUpgradeOperation method execute.
@Override
public void execute(final String site) throws UpgradeException {
Path descriptorFile = getRepositoryPath(site).getParent().resolve(descriptorPath);
if (Files.notExists(descriptorFile)) {
logger.info("Plugin descriptor file not found for site {0}", site);
return;
}
try (Reader reader = Files.newBufferedReader(descriptorFile)) {
PluginDescriptor descriptor = descriptorReader.read(reader);
if (descriptor.getDescriptorVersion().equals(descriptorVersion)) {
logger.info("Plugin descriptor already update for site " + site);
return;
}
logger.info("Updating plugin descriptor for site " + site);
doPluginDescriptorUpdates(descriptor);
descriptor.setDescriptorVersion(descriptorVersion);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(new DisableClassLoadingConstructor(), new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
if (propertyValue != null) {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
return null;
}
}, options);
String content = yaml.dumpAsMap(descriptor);
writeToRepo(site, descriptorPath, new ByteArrayInputStream(content.getBytes()));
commitAllChanges(site);
} catch (Exception e) {
throw new UpgradeException("Plugin descriptor can't be read for site " + site);
}
}
use of org.craftercms.studio.api.v2.exception.UpgradeException in project studio by craftercms.
the class AbstractContentTypeUpgradeOperation method shouldBeUpdated.
@Override
protected boolean shouldBeUpdated(final String site, final Path file) throws UpgradeException {
logger.debug("Checking file {0} for site {1}", file, site);
try {
Document document = loadDocument(file);
String contentTypeName = (String) select(document, contentTypeXpath, XPathConstants.STRING);
if (CollectionUtils.isNotEmpty(includedContentTypes) && !includedContentTypes.contains(contentTypeName)) {
logger.debug("File {0} of content-type {1} will not be updated", file, contentTypeName);
return false;
}
if (StringUtils.isNotEmpty(formDefinitionXpath)) {
Path formDefinition = getFormDefinition(site, contentTypeName);
document = loadDocument(formDefinition);
return (Boolean) select(document, formDefinitionXpath, XPathConstants.BOOLEAN);
} else {
return true;
}
} catch (ExecutionException e) {
logger.error("Invalid XML file found at " + file, e);
return false;
} catch (Exception e) {
throw new UpgradeException("Error parsing xml file " + file, e);
}
}
Aggregations