|
| 1 | +#!/usr/bin/env perl |
| 2 | + |
| 3 | +#------------------------------------------------------------------- |
| 4 | +# WebGUI is Copyright 2001-2009 Plain Black Corporation. |
| 5 | +#------------------------------------------------------------------- |
| 6 | +# Please read the legal notices (docs/legal.txt) and the license |
| 7 | +# (docs/license.txt) that came with this distribution before using |
| 8 | +# this software. |
| 9 | +#------------------------------------------------------------------- |
| 10 | +# http://www.plainblack.com info@plainblack.com |
| 11 | +#------------------------------------------------------------------- |
| 12 | + |
| 13 | +our ($webguiRoot); |
| 14 | + |
| 15 | +BEGIN { |
| 16 | + $webguiRoot = "../.."; |
| 17 | + unshift (@INC, $webguiRoot."/lib"); |
| 18 | +} |
| 19 | + |
| 20 | +use strict; |
| 21 | +use Getopt::Long; |
| 22 | +use WebGUI::Session; |
| 23 | +use WebGUI::Storage; |
| 24 | +use WebGUI::Asset; |
| 25 | + |
| 26 | + |
| 27 | +my $toVersion = '7.10.25'; |
| 28 | +my $quiet; # this line required |
| 29 | + |
| 30 | + |
| 31 | +my $session = start(); # this line required |
| 32 | + |
| 33 | +# upgrade functions go here |
| 34 | + |
| 35 | +finish($session); # this line required |
| 36 | + |
| 37 | + |
| 38 | +#---------------------------------------------------------------------------- |
| 39 | +# Describe what our function does |
| 40 | +#sub exampleFunction { |
| 41 | +# my $session = shift; |
| 42 | +# print "\tWe're doing some stuff here that you should know about... " unless $quiet; |
| 43 | +# # and here's our code |
| 44 | +# print "DONE!\n" unless $quiet; |
| 45 | +#} |
| 46 | + |
| 47 | + |
| 48 | +# -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- |
| 49 | + |
| 50 | +#---------------------------------------------------------------------------- |
| 51 | +# Add a package to the import node |
| 52 | +sub addPackage { |
| 53 | + my $session = shift; |
| 54 | + my $file = shift; |
| 55 | + |
| 56 | + print "\tUpgrading package $file\n" unless $quiet; |
| 57 | + # Make a storage location for the package |
| 58 | + my $storage = WebGUI::Storage->createTemp( $session ); |
| 59 | + $storage->addFileFromFilesystem( $file ); |
| 60 | + |
| 61 | + # Import the package into the import node |
| 62 | + my $package = eval { |
| 63 | + my $node = WebGUI::Asset->getImportNode($session); |
| 64 | + $node->importPackage( $storage, { |
| 65 | + overwriteLatest => 1, |
| 66 | + clearPackageFlag => 1, |
| 67 | + setDefaultTemplate => 1, |
| 68 | + } ); |
| 69 | + }; |
| 70 | + |
| 71 | + if ($package eq 'corrupt') { |
| 72 | + die "Corrupt package found in $file. Stopping upgrade.\n"; |
| 73 | + } |
| 74 | + if ($@ || !defined $package) { |
| 75 | + die "Error during package import on $file: $@\nStopping upgrade\n."; |
| 76 | + } |
| 77 | + |
| 78 | + return; |
| 79 | +} |
| 80 | + |
| 81 | +#------------------------------------------------- |
| 82 | +sub start { |
| 83 | + my $configFile; |
| 84 | + $|=1; #disable output buffering |
| 85 | + GetOptions( |
| 86 | + 'configFile=s'=>\$configFile, |
| 87 | + 'quiet'=>\$quiet |
| 88 | + ); |
| 89 | + my $session = WebGUI::Session->open($webguiRoot,$configFile); |
| 90 | + $session->user({userId=>3}); |
| 91 | + my $versionTag = WebGUI::VersionTag->getWorking($session); |
| 92 | + $versionTag->set({name=>"Upgrade to ".$toVersion}); |
| 93 | + return $session; |
| 94 | +} |
| 95 | + |
| 96 | +#------------------------------------------------- |
| 97 | +sub finish { |
| 98 | + my $session = shift; |
| 99 | + updateTemplates($session); |
| 100 | + my $versionTag = WebGUI::VersionTag->getWorking($session); |
| 101 | + $versionTag->commit; |
| 102 | + $session->db->write("insert into webguiVersion values (".$session->db->quote($toVersion).",'upgrade',".time().")"); |
| 103 | + $session->close(); |
| 104 | +} |
| 105 | + |
| 106 | +#------------------------------------------------- |
| 107 | +sub updateTemplates { |
| 108 | + my $session = shift; |
| 109 | + return undef unless (-d "packages-".$toVersion); |
| 110 | + print "\tUpdating packages.\n" unless ($quiet); |
| 111 | + opendir(DIR,"packages-".$toVersion); |
| 112 | + my @files = readdir(DIR); |
| 113 | + closedir(DIR); |
| 114 | + my $newFolder = undef; |
| 115 | + foreach my $file (@files) { |
| 116 | + next unless ($file =~ /\.wgpkg$/); |
| 117 | + # Fix the filename to include a path |
| 118 | + $file = "packages-" . $toVersion . "/" . $file; |
| 119 | + addPackage( $session, $file ); |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +#vim:ft=perl |
0 commit comments