infopark_reactor_migrations 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +165 -0
  4. data/README +64 -0
  5. data/Rakefile +19 -0
  6. data/infopark_reactor_migrations.gemspec +27 -0
  7. data/lib/generators/cm/migration/USAGE +8 -0
  8. data/lib/generators/cm/migration/migration_generator.rb +15 -0
  9. data/lib/generators/cm/migration/templates/template.rb +7 -0
  10. data/lib/infopark_reactor_migrations.rb +29 -0
  11. data/lib/reactor/cm/attribute.rb +84 -0
  12. data/lib/reactor/cm/bridge.rb +49 -0
  13. data/lib/reactor/cm/editorial_group.rb +22 -0
  14. data/lib/reactor/cm/group.rb +270 -0
  15. data/lib/reactor/cm/language.rb +56 -0
  16. data/lib/reactor/cm/link.rb +132 -0
  17. data/lib/reactor/cm/live_group.rb +22 -0
  18. data/lib/reactor/cm/missing_credentials.rb +7 -0
  19. data/lib/reactor/cm/obj.rb +402 -0
  20. data/lib/reactor/cm/obj_class.rb +186 -0
  21. data/lib/reactor/cm/object_base.rb +164 -0
  22. data/lib/reactor/cm/user.rb +100 -0
  23. data/lib/reactor/cm/workflow.rb +40 -0
  24. data/lib/reactor/cm/xml_attribute.rb +35 -0
  25. data/lib/reactor/cm/xml_markup.rb +85 -0
  26. data/lib/reactor/cm/xml_request.rb +82 -0
  27. data/lib/reactor/cm/xml_request_error.rb +16 -0
  28. data/lib/reactor/cm/xml_response.rb +41 -0
  29. data/lib/reactor/configuration.rb +7 -0
  30. data/lib/reactor/migration.rb +82 -0
  31. data/lib/reactor/migrations/railtie.rb +10 -0
  32. data/lib/reactor/migrations/version.rb +5 -0
  33. data/lib/reactor/plans/common_attribute.rb +32 -0
  34. data/lib/reactor/plans/common_group.rb +44 -0
  35. data/lib/reactor/plans/common_obj_class.rb +69 -0
  36. data/lib/reactor/plans/create_attribute.rb +32 -0
  37. data/lib/reactor/plans/create_group.rb +34 -0
  38. data/lib/reactor/plans/create_obj.rb +48 -0
  39. data/lib/reactor/plans/create_obj_class.rb +28 -0
  40. data/lib/reactor/plans/delete_attribute.rb +23 -0
  41. data/lib/reactor/plans/delete_group.rb +28 -0
  42. data/lib/reactor/plans/delete_obj.rb +22 -0
  43. data/lib/reactor/plans/delete_obj_class.rb +22 -0
  44. data/lib/reactor/plans/prepared.rb +15 -0
  45. data/lib/reactor/plans/rename_group.rb +32 -0
  46. data/lib/reactor/plans/rename_obj_class.rb +24 -0
  47. data/lib/reactor/plans/update_attribute.rb +23 -0
  48. data/lib/reactor/plans/update_group.rb +30 -0
  49. data/lib/reactor/plans/update_obj.rb +30 -0
  50. data/lib/reactor/plans/update_obj_class.rb +26 -0
  51. data/lib/reactor/tools/migrator.rb +135 -0
  52. data/lib/reactor/tools/response_handler/base.rb +22 -0
  53. data/lib/reactor/tools/response_handler/string.rb +19 -0
  54. data/lib/reactor/tools/response_handler/xml_attribute.rb +52 -0
  55. data/lib/reactor/tools/smart_xml_logger.rb +69 -0
  56. data/lib/reactor/tools/sower.rb +89 -0
  57. data/lib/reactor/tools/uploader.rb +131 -0
  58. data/lib/reactor/tools/versioner.rb +120 -0
  59. data/lib/reactor/tools/xml_attributes.rb +70 -0
  60. data/lib/tasks/cm_migrate.rake +8 -0
  61. data/lib/tasks/cm_seeds.rake +41 -0
  62. metadata +193 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .rvmrc
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in infopark_reactor_migrations.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,64 @@
1
+ infopark_reactor_migrations
2
+ ===========
3
+
4
+ Reactor::Migrations is a Rails 3 gem that makes working with Fiona just as easy as with Rails native migrations. Reactor::Migrations stores it's versioning information inside CM and thus it is compatible with all backup solutions. Please note the fact, that Reactor cannot account for manual modifications made to the CM (although it gives it's best)
5
+
6
+
7
+ Disclaimer
8
+ ==========
9
+
10
+ The code has been deployed and run for months. It showed itself to be stable and dependable. It may not work for you, although it should.
11
+
12
+
13
+ Installation
14
+ ============
15
+
16
+ config/initializers/reactor.rb:
17
+ Reactor::Configuration.xml_access = {
18
+ :host => 'localhost', # Fiona host
19
+ :port => 6001, # CM http port (TCL port + 1)
20
+ :id => '1234', # leave it as is
21
+
22
+ :username => 'root', # default user for all requests
23
+ :secret => 'MYSECRET' # instance secret!
24
+ }
25
+
26
+ Example
27
+ =======
28
+
29
+ > rails g cm:migration ExampleMigration
30
+
31
+ edit cm/migrate/[timestamp]_example_migration.rb
32
+ ...
33
+ def self.up
34
+ create_attribute :name => "test_attribute", :type => "enum" do
35
+ set :values, ["value1", "value2"]
36
+ set :title, "test attr"
37
+ end
38
+ create_class :name => "ExampleClass", :title =>"Beispiel", :type => "publication" do
39
+ set :title, {"Beispielvorlage" => {:lang => :de}, "Example obj class" => {:lang => :en}}
40
+ take :authors, :mandatory => true # adds existing mandatory ! attribute named "authors"
41
+ take :contributors # adds existing attribute named "authors"
42
+ take :test_attribute, :preset => "value2" # we just created it!
43
+ end
44
+ end
45
+
46
+ def self.down
47
+ delete_class :name => 'ExampleClass'
48
+ delete_attribute :name => 'test_attribute'
49
+ end
50
+ ...
51
+ and finally
52
+
53
+ > rake cm:migrate
54
+
55
+ You can also type
56
+
57
+ > rake cm:migrate VERSION=0
58
+
59
+ to revert any changes (VERSION allows you to migrate to a specific version too).
60
+
61
+ That's all! Enjoy!
62
+
63
+
64
+ Copyright (c) 2011 Tomasz Przedmojski, tomasz.przedmojski@infopark.de, Infopark AG
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+
5
+ # remove this task, when this gem is distributed as a `real` gem (and not included in Gemfile through `:path =>` )
6
+ task :update_gemspec_for_distribution do
7
+
8
+ fn = Dir[File.expand_path('../*.gemspec', __FILE__)].first
9
+ source_gemspec = File.read(fn)
10
+
11
+ source_gemspec.gsub!(/^([\t ]*)((s.files\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files`.split("\n").inspect}\n"}
12
+ source_gemspec.gsub!(/^([\t ]*)((s.test_files\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files -- {test,spec,features}/*`.split("\n").inspect}\n"}
13
+ source_gemspec.gsub!(/^([\t ]*)((s.executables\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }.inspect}\n"}
14
+
15
+ File.open("#{fn}.resolved", 'w') do |f|
16
+ f.write source_gemspec
17
+ end
18
+
19
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "reactor/migrations/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "infopark_reactor_migrations"
7
+ s.version = "#{Reactor::Migrations::VERSION}"
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tomasz Przedmojski"]
10
+ s.email = ["tomasz.przedmojski@infopark.de"]
11
+ s.homepage = ""
12
+ s.summary = %q{The power of rails migrations for Inforpark Fiona CMS}
13
+ s.description = %q{Create classes, attributes, store version information and synchronize multiple servers with one command.}
14
+ s.license = 'LGPL-3'
15
+
16
+ #s.rubyforge_project = "infopark_reactor_migrations"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'rails', '>= 3.0.10', '<= 3.2.9'
24
+ s.add_dependency 'term-ansicolor'
25
+ s.add_dependency 'nokogiri'
26
+ s.add_development_dependency 'rspec'
27
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Creates CM Migration with given name. Name should be CamelCased.
3
+
4
+ Example:
5
+ rails g cm:migration MigrationName
6
+
7
+ This will create:
8
+ cm/migration/[timestamp]_migration_name.rb
@@ -0,0 +1,15 @@
1
+ module Cm
2
+ module Generators
3
+ class MigrationGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::Migration
5
+ def self.next_migration_number(dirname)
6
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
7
+ end
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+ def create_migration_file
11
+ migration_template "template.rb", "cm/migrate/#{file_name}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %> < Reactor::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # require config
2
+ require 'reactor/configuration'
3
+
4
+ # railtie
5
+ require 'reactor/migrations/railtie' if defined?(Rails)
6
+
7
+ # require components
8
+ require 'reactor/cm/bridge'
9
+ require 'reactor/cm/language'
10
+ require 'reactor/cm/object_base'
11
+ require 'reactor/cm/user'
12
+ require 'reactor/cm/attribute'
13
+ require 'reactor/cm/obj'
14
+ require 'reactor/cm/obj_class'
15
+ require 'reactor/cm/link'
16
+ require 'reactor/cm/group'
17
+ require 'reactor/cm/editorial_group'
18
+ require 'reactor/cm/live_group'
19
+ require 'reactor/cm/workflow'
20
+
21
+ # require main class
22
+ require 'reactor/migration'
23
+
24
+ # require misc
25
+ require 'reactor/cm/xml_request_error'
26
+ require 'reactor/cm/missing_credentials'
27
+
28
+ # require public tools
29
+ require 'reactor/tools/uploader'
@@ -0,0 +1,84 @@
1
+ module Reactor
2
+ module Cm
3
+ class Attribute
4
+ def self.exists?(name)
5
+ begin
6
+ return Attribute.new.send(:get,name).ok?
7
+ rescue
8
+ return false
9
+ end
10
+ end
11
+
12
+ def self.get(name)
13
+ attr = Attribute.new
14
+ attr.send(:get,name)
15
+ attr
16
+ end
17
+
18
+ def self.create(name, type)
19
+ attr = Attribute.new
20
+ attr.send(:create,name,type)
21
+ attr
22
+ end
23
+
24
+ def set(key, value)
25
+ @params[key.to_sym] = value
26
+ end
27
+
28
+ def save!
29
+ request = XmlRequest.prepare do |xml|
30
+ xml.where_key_tag!(base_name, 'name', @name)
31
+ xml.set_tag!(base_name) do
32
+ @params.each do |key, value|
33
+ xml.value_tag!(key.to_s, value)
34
+ end
35
+ end
36
+ end
37
+ response = request.execute!
38
+ end
39
+
40
+ def delete!
41
+ request = XmlRequest.prepare do |xml|
42
+ xml.where_key_tag!(base_name, 'name', @name)
43
+ xml.tag!("#{base_name}-delete")
44
+ end
45
+ response = request.execute!
46
+ end
47
+
48
+ protected
49
+ def base_name
50
+ 'attribute'
51
+ end
52
+
53
+ def initialize
54
+ @params = {}
55
+ end
56
+
57
+ def get(name)
58
+ request = XmlRequest.prepare do |xml|
59
+ xml.where_key_tag!(base_name, 'name', name)
60
+ xml.get_key_tag!(base_name, 'name')
61
+ end
62
+ response = request.execute!
63
+ @name = name
64
+ response
65
+ end
66
+
67
+ def create(name, type)
68
+ request = XmlRequest.prepare do |xml|
69
+ xml.create_tag!(base_name) do
70
+ xml.tag!('name') do
71
+ xml.text!(name)
72
+ end
73
+ xml.tag!('type') do
74
+ xml.text!(type)
75
+ end
76
+ end
77
+ end
78
+ response = request.execute!
79
+ @name = name
80
+ response
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,49 @@
1
+ module Reactor
2
+ module Cm
3
+ class Bridge
4
+ # credit goes to Anton
5
+ def self.login_for(sessionId)
6
+ old_username = Reactor::Configuration.xml_access[:username]
7
+ Reactor::Configuration.xml_access[:username] = 'root'
8
+ begin
9
+ response = Reactor::Cm::XmlRequest.prepare do |xml|
10
+ xml.tag!('licenseManager-logins')
11
+ end.execute!
12
+ login = nil
13
+ result = response.xpath('//licenseManager-logins/listitem')
14
+ result = [result] unless result.kind_of?(Array)
15
+ result.each do |login_data_element|
16
+ properties = deserialize_login_data(login_data_element.text)
17
+ if properties[:sessionId] == sessionId && properties[:interface] == "X"
18
+ login = properties[:login]
19
+ break
20
+ end
21
+ end
22
+ login
23
+ rescue => e
24
+ Rails.logger.error "Login to CM failed! #{e.class}: #{e.message}"
25
+ nil
26
+ ensure
27
+ Reactor::Configuration.xml_access[:username] = old_username
28
+ end
29
+ end
30
+
31
+ private
32
+ def self.deserialize_login_data(serialized_property_list)
33
+ entry_delimiter = /;\r?\n/
34
+ no_braces = serialized_property_list[1..(serialized_property_list.rindex(entry_delimiter) - 1)]
35
+ property_list_lines = no_braces.split(entry_delimiter)
36
+ property_list_lines.inject(properties = {}) do |map, line|
37
+ key, value = line.strip.scan(/^([^=]*) = (.*)$/).first
38
+ if value[0..0] == '"'
39
+ value = value[1..(value.length - 2)]
40
+ value.gsub!(/\\(.)/, '\1')
41
+ end
42
+ map[key.to_sym] = value
43
+ map
44
+ end
45
+ properties
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ require 'reactor/cm/group'
2
+
3
+ module Reactor
4
+
5
+ module Cm
6
+
7
+ # The EditorialGroup class respects the user management configured in the content manager and
8
+ # handles all editorial groups. See @Group for further details.
9
+ class EditorialGroup < Group
10
+
11
+ protected
12
+
13
+ # Overwritten method from +Group+.
14
+ def base_name
15
+ 'groupProxy'
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end