brightpearl-cli 1.4.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/phpunit/IntegrationTestCase.php +512 -0
- data/assets/phpunit/JournalEntries.php +246 -0
- data/assets/phpunit/Message.php +101 -0
- data/assets/phpunit/Providers.php +404 -0
- data/assets/phpunit/RedirectException.php +20 -0
- data/assets/phpunit/ReservedContactIds.php +27 -0
- data/assets/phpunit/Values.php +30 -0
- data/assets/phpunit/bootstrap.php +85 -0
- data/assets/phpunit/jenkins-bootstrap.php +60 -0
- data/lib/brightpearl_cli.rb +26 -9
- data/lib/core/config.rb +1 -1
- data/lib/core/ebay.rb +11 -0
- data/lib/core/ebay_factory.rb +34 -0
- data/lib/core/enums.rb +8 -0
- data/lib/core/git.rb +44 -2
- data/lib/core/git_delete.rb +57 -15
- data/lib/core/mysql.rb +13 -13
- data/lib/core/pom.rb +44 -21
- data/lib/core/sql_update.rb +24 -0
- data/lib/core/terminal.rb +5 -4
- data/lib/core/utils_files.rb +0 -8
- data/lib/core/vm.rb +62 -0
- data/lib/routes/dummy_order.rb +0 -1
- data/lib/routes/fix.rb +30 -5
- data/lib/routes/git_checkout.rb +7 -2
- data/lib/routes/git_delete.rb +9 -3
- data/lib/routes/git_merge.rb +22 -6
- data/lib/routes/git_update.rb +1 -1
- data/lib/routes/production_logs.rb +4 -4
- data/lib/routes/review.rb +8 -2
- data/lib/routes/scripts_sonar.rb +6 -2
- data/lib/routes/scripts_sql_update.rb +33 -0
- data/lib/routes/test.rb +23 -8
- data/lib/version.rb +1 -0
- data/vm-scripts/sql-updates.sh +9 -0
- metadata +18 -2
data/lib/core/git_delete.rb
CHANGED
@@ -6,6 +6,8 @@ module App
|
|
6
6
|
|
7
7
|
@git = git.nil? ? App::Git.new : git
|
8
8
|
|
9
|
+
branch_info = @git.branch_data(branch_name)
|
10
|
+
|
9
11
|
App::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", App::Terminal::MSG_TODO)
|
10
12
|
App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)
|
11
13
|
|
@@ -16,12 +18,20 @@ module App
|
|
16
18
|
end
|
17
19
|
|
18
20
|
@git.repo_loop.each do |repo_dir|
|
19
|
-
commands = []
|
20
21
|
if @git.current_branch_for_repo(repo_dir) == branch_name
|
21
|
-
|
22
|
+
App::Terminal::command("git checkout #{App::Git::MASTER}", repo_dir)
|
23
|
+
end
|
24
|
+
if (repo_dir == App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE) && branch_info[0][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"]) || (repo_dir == App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE) && branch_info[0][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"])
|
25
|
+
commands = [
|
26
|
+
"git branch --unset-upstream #{branch_name}",
|
27
|
+
"git branch -d #{branch_name}"
|
28
|
+
]
|
29
|
+
results = App::Terminal::command(commands, repo_dir)
|
30
|
+
handle_results_1(branch_name, repo_dir, results)
|
31
|
+
else
|
32
|
+
App::Terminal::output("Skipping #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} because branch #{App::Terminal::format_branch(branch_name)} doesn't exist there.", App::Terminal::MSG_WARNING)
|
22
33
|
end
|
23
|
-
|
24
|
-
App::Terminal::command_capture(commands, repo_dir)
|
34
|
+
|
25
35
|
end
|
26
36
|
|
27
37
|
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
@@ -45,11 +55,15 @@ module App
|
|
45
55
|
puts "Branch \x1B[32m[#{branch_name}]\x1B[0m not found in: \x1B[33m#{repo_dir}\x1B[0m. Aborting \x1B[35mREMOTE DELETE\x1B[0m for this repo."
|
46
56
|
next
|
47
57
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
]
|
52
|
-
|
58
|
+
|
59
|
+
# This is hacky (but no time) !
|
60
|
+
results = App::Terminal::command("git branch --unset-upstream #{branch_name}", repo_dir)
|
61
|
+
results[1] = true
|
62
|
+
handle_results_1(branch_name, repo_dir, results)
|
63
|
+
|
64
|
+
results = App::Terminal::command("git push origin --delete #{branch_name}", repo_dir)
|
65
|
+
handle_results_2(branch_name, repo_dir, results)
|
66
|
+
|
53
67
|
end
|
54
68
|
|
55
69
|
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
@@ -70,20 +84,48 @@ module App
|
|
70
84
|
end
|
71
85
|
|
72
86
|
@git.repo_loop.each do |repo_dir|
|
73
|
-
commands = []
|
74
87
|
if @git.current_branch_for_repo(repo_dir) == branch_name
|
75
|
-
|
88
|
+
App::Terminal::command("git checkout #{App::Git::MASTER}", repo_dir)
|
76
89
|
end
|
77
|
-
|
78
|
-
commands
|
79
|
-
|
80
|
-
|
90
|
+
|
91
|
+
commands = [
|
92
|
+
"git branch --unset-upstream #{branch_name}",
|
93
|
+
"git branch -d #{branch_name}"
|
94
|
+
]
|
95
|
+
results = App::Terminal::command(commands, repo_dir)
|
96
|
+
handle_results_1(branch_name, repo_dir, results)
|
97
|
+
|
98
|
+
commands = [
|
99
|
+
"git push origin --delete #{branch_name}"
|
100
|
+
]
|
101
|
+
results = App::Terminal::command(commands, repo_dir)
|
102
|
+
handle_results_2(branch_name, repo_dir, results)
|
103
|
+
|
81
104
|
end
|
82
105
|
|
83
106
|
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} and #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
84
107
|
|
85
108
|
end
|
86
109
|
|
110
|
+
private
|
111
|
+
|
112
|
+
def self.handle_results_1(branch_name, repo_dir, results)
|
113
|
+
unless results[0]
|
114
|
+
App::Terminal::output("The branch #{App::Terminal::format_branch(branch_name)} in #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} has #{App::Terminal::format_highlight('no upstream information')}.", App::Terminal::MSG_WARNING)
|
115
|
+
end
|
116
|
+
unless results[1]
|
117
|
+
if App::Terminal::prompt_yes_no("The branch #{App::Terminal::format_branch(branch_name)} in #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} is #{App::Terminal::format_invalid('not fully merged!', true)}", nil, "Are you #{App::Terminal::format_action('absolutely sure')}\x1B[38;5;89m you want to delete it?");
|
118
|
+
App::Terminal::command("git branch -D #{branch_name}", repo_dir)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.handle_results_2(branch_name, repo_dir, results)
|
124
|
+
unless results[0]
|
125
|
+
App::Terminal::output("#{App::Terminal::format_branch(branch_name)} in #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} has #{App::Terminal::format_invalid('no remote branch to delete')}.", App::Terminal::MSG_WARNING)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
87
129
|
end
|
88
130
|
|
89
131
|
end
|
data/lib/core/mysql.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'mysql2'
|
2
2
|
|
3
3
|
module App
|
4
4
|
|
@@ -16,11 +16,11 @@ module App
|
|
16
16
|
def self.vm(schema = DEFAULT_VM_SCHEMA)
|
17
17
|
|
18
18
|
if @vm_connection[schema].nil?
|
19
|
-
@vm_connection[schema] =
|
20
|
-
App::Config.param(App::Config::VM_IP),
|
21
|
-
App::Config.param(App::Config::VM_MYSQL_USER),
|
22
|
-
App::Config.param(App::Config::VM_MYSQL_PASSWORD),
|
23
|
-
schema
|
19
|
+
@vm_connection[schema] = Mysql2::Client.new(
|
20
|
+
:host => App::Config.param(App::Config::VM_IP),
|
21
|
+
:username => App::Config.param(App::Config::VM_MYSQL_USER),
|
22
|
+
:password => App::Config.param(App::Config::VM_MYSQL_PASSWORD),
|
23
|
+
:database => schema
|
24
24
|
)
|
25
25
|
end
|
26
26
|
@vm_connection[schema]
|
@@ -38,11 +38,11 @@ module App
|
|
38
38
|
if host.nil? || user.nil? || pass.nil? || host == '' || user == '' || pass == ''
|
39
39
|
App::Terminal::error('EC2 access data not found', ["The command you're trying to run requires access to an EC2 database.", "In order for this to work you will need valid #{App::Terminal::format_highlight('access data')}.", "Please speak to #{App::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true)
|
40
40
|
end
|
41
|
-
@ec2_connection =
|
42
|
-
encrypter.decrypt(host),
|
43
|
-
encrypter.decrypt(user),
|
44
|
-
encrypter.decrypt(pass),
|
45
|
-
schema
|
41
|
+
@ec2_connection = Mysql2::Client.new(
|
42
|
+
:host => encrypter.decrypt(host),
|
43
|
+
:username => encrypter.decrypt(user),
|
44
|
+
:password => encrypter.decrypt(pass),
|
45
|
+
:database => schema
|
46
46
|
)
|
47
47
|
end
|
48
48
|
@ec2_connection
|
@@ -52,7 +52,7 @@ module App
|
|
52
52
|
def self.get_random_customer_id
|
53
53
|
unless @ids_customers.any?
|
54
54
|
customers = App::MySQL::vm.query('SELECT customers_id FROM customers ORDER BY customers_id DESC LIMIT 100')
|
55
|
-
customers.
|
55
|
+
customers.each do |row|
|
56
56
|
@ids_customers << row['customers_id']
|
57
57
|
end
|
58
58
|
end
|
@@ -62,7 +62,7 @@ module App
|
|
62
62
|
def self.get_random_shipping_id
|
63
63
|
unless @ids_shipping.any?
|
64
64
|
ship_methods = App::MySQL::vm.query('SELECT ship_method_id FROM ship_methods ORDER BY ship_method_id DESC LIMIT 100')
|
65
|
-
ship_methods.
|
65
|
+
ship_methods.each do |row|
|
66
66
|
@ids_shipping << row['ship_method_id']
|
67
67
|
end
|
68
68
|
end
|
data/lib/core/pom.rb
CHANGED
@@ -2,11 +2,6 @@ module App
|
|
2
2
|
|
3
3
|
class Pom
|
4
4
|
|
5
|
-
# Initialise credentials
|
6
|
-
# @return void
|
7
|
-
def initialize
|
8
|
-
end
|
9
|
-
|
10
5
|
# Retrieves list of pom.xml files which need to be un-snapshotted
|
11
6
|
# @return Array
|
12
7
|
def self.get_files_to_change
|
@@ -66,18 +61,29 @@ module App
|
|
66
61
|
File.open(filename, 'w') { |file| file.puts contents_new }
|
67
62
|
end
|
68
63
|
|
64
|
+
red_versions = []
|
65
|
+
green_versions = []
|
66
|
+
|
69
67
|
diff_result = App::Terminal::command_capture('git diff | grep "+ \|- "', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
70
68
|
puts
|
71
69
|
diff_result[0].split("\n").each do |line|
|
72
70
|
if line[0] == '+'
|
73
71
|
puts " \x1B[38;5;46m#{line.gsub(' ', '')}\x1B[0m"
|
72
|
+
green_versions << get_version_from_line(line)
|
74
73
|
else
|
75
74
|
puts " \x1B[38;5;196m#{line.gsub(' ', '')}\x1B[0m"
|
75
|
+
red_versions << get_version_from_line(line)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
puts
|
79
79
|
|
80
|
-
|
80
|
+
if red_versions != green_versions
|
81
|
+
unless App::Terminal::prompt_yes_no('POM version conflict occurred', ['Unable to successfully Un-snapshot POMs.', 'Please fix the POM versions before continuing.'], 'POMs fixed and ready to continue?')
|
82
|
+
App::Terminal::abort(nil, nil, true, false)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
App::Terminal::command_capture(['git add .', 'git status'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
81
87
|
|
82
88
|
# Figure out the commit message.
|
83
89
|
git = App::Git.new
|
@@ -87,25 +93,37 @@ module App
|
|
87
93
|
else
|
88
94
|
jira_number = '0000'
|
89
95
|
end
|
90
|
-
commit_message = "BP-#{jira_number} Updated POM tags on #{current_branch_code_repo}."
|
91
96
|
|
92
|
-
|
97
|
+
if current_branch_code_repo == App::Git::MASTER
|
98
|
+
commit_message = "BP-#{jira_number} Removed POM tags."
|
99
|
+
else
|
100
|
+
commit_message = "BP-#{jira_number} Updated POM tags on #{current_branch_code_repo}."
|
101
|
+
end
|
93
102
|
|
94
|
-
|
95
|
-
App::Terminal::command(["git commit -m '#{commit_message.gsub("'", "\\'")}'"], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
96
|
-
else
|
97
|
-
App::Terminal::info('Un-snapshotting complete', "Please note that your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('committed')} to Git.", false)
|
98
|
-
return
|
99
|
-
end
|
103
|
+
git = App::Git.new
|
100
104
|
|
101
|
-
|
102
|
-
App::Terminal::command('git push', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
103
|
-
App::Terminal::info('Un-snapshotting complete', "Your POMs have been un-snapshotted, the changes #{App::Terminal::format_action('committed')} to Git and #{App::Terminal::format_action('pushed')} to origin.")
|
104
|
-
else
|
105
|
-
App::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted and the changes #{App::Terminal::format_action('committed')} to Git.", 'However, nothing has been pushed to origin. You will need to do this manually.'], false)
|
106
|
-
end
|
107
|
-
else
|
105
|
+
if git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE)) == App::Git::MASTER
|
108
106
|
App::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted. However, nothing has been committed to Git or pushed to origin because you are on #{App::Git::MASTER}.", 'You will need to do this manually.'], false)
|
107
|
+
else
|
108
|
+
|
109
|
+
if git.changes_exist(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE))
|
110
|
+
|
111
|
+
if App::Terminal::prompt_yes_no('Commit to GIT', ["This will commit your changes to GIT with message: #{App::Terminal::format_highlight(commit_message)}"])
|
112
|
+
App::Terminal::command(["git commit -m '#{commit_message.gsub("'", "\\'")}'"], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
113
|
+
else
|
114
|
+
App::Terminal::info('Un-snapshotting complete', "Please note that your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('committed')} to Git.", false)
|
115
|
+
return
|
116
|
+
end
|
117
|
+
|
118
|
+
if App::Terminal::prompt_yes_no('Push changes to origin')
|
119
|
+
App::Terminal::command('git push', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
120
|
+
App::Terminal::info('Un-snapshotting complete', "Your POMs have been un-snapshotted, the changes #{App::Terminal::format_action('committed')} to Git and #{App::Terminal::format_action('pushed')} to origin.")
|
121
|
+
else
|
122
|
+
App::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted and the changes #{App::Terminal::format_action('committed')} to Git.", 'However, nothing has been pushed to origin. You will need to do this manually.'], false)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
109
127
|
end
|
110
128
|
|
111
129
|
end
|
@@ -124,6 +142,11 @@ module App
|
|
124
142
|
|
125
143
|
end
|
126
144
|
|
145
|
+
def self.get_version_from_line(line)
|
146
|
+
version = line.match(/>\d{1,2}.\d{1,2}.\d{1,2}-/)
|
147
|
+
version[0].gsub('>', '').gsub('-', '')
|
148
|
+
end
|
149
|
+
|
127
150
|
end
|
128
151
|
|
129
152
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class SqlUpdate
|
4
|
+
|
5
|
+
def self.run_sql_update
|
6
|
+
|
7
|
+
unless App::Terminal::prompt_yes_no("You're about to run the SQL update script", ["Please note this script is still in #{App::Terminal::format_highlight('BETA')} and will only work under certain (assumed) circumstances."])
|
8
|
+
App::Terminal::abort(nil, nil, true, false)
|
9
|
+
end
|
10
|
+
|
11
|
+
@git = App::Git::new
|
12
|
+
|
13
|
+
App::Terminal::output('Checking that both your repositories are on the same branch')
|
14
|
+
@git.check_for_same_branch(App::Git::SAME_BRANCH_ERROR)
|
15
|
+
|
16
|
+
branch_number = @git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB))
|
17
|
+
|
18
|
+
puts branch_number
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/core/terminal.rb
CHANGED
@@ -123,7 +123,7 @@ module App
|
|
123
123
|
if preceding_blank_line
|
124
124
|
puts
|
125
125
|
end
|
126
|
-
puts " \x1B[48;5;
|
126
|
+
puts " \x1B[48;5;240m Message \x1B[0m \xe2\x86\x92 #{title}"
|
127
127
|
parse_messages(message)
|
128
128
|
end
|
129
129
|
|
@@ -136,7 +136,7 @@ module App
|
|
136
136
|
if preceding_blank_line
|
137
137
|
puts
|
138
138
|
end
|
139
|
-
puts " \x1B[48;5;
|
139
|
+
puts " \x1B[48;5;12m Success \x1B[0m \xe2\x86\x92 #{title}"
|
140
140
|
parse_messages(message)
|
141
141
|
end
|
142
142
|
|
@@ -302,10 +302,11 @@ module App
|
|
302
302
|
end
|
303
303
|
table(:border => false) do
|
304
304
|
messages.each do |line|
|
305
|
-
|
305
|
+
new_line = line
|
306
|
+
new_line = line.gsub("\x1B[0m", "\x1B[38;5;240m") unless line.nil?
|
306
307
|
row do
|
307
308
|
column('', :align => 'left', :width => 4)
|
308
|
-
column("\x1B[38;5;240m#{
|
309
|
+
column("\x1B[38;5;240m#{new_line}\x1B[0m", :align => 'left', :width => 180)
|
309
310
|
end
|
310
311
|
end
|
311
312
|
end
|
data/lib/core/utils_files.rb
CHANGED
@@ -34,8 +34,6 @@ module App
|
|
34
34
|
file.close
|
35
35
|
}
|
36
36
|
|
37
|
-
add_file_to_git(full_path_and_file)
|
38
|
-
|
39
37
|
rescue Exception => e
|
40
38
|
|
41
39
|
App::Terminal::error('Something went wrong', "#{e.message}", true)
|
@@ -81,12 +79,6 @@ module App
|
|
81
79
|
files
|
82
80
|
end
|
83
81
|
|
84
|
-
def self.add_file_to_git(full_path_and_file)
|
85
|
-
|
86
|
-
App::Terminal::error('Must program add_file_to_git', "#{full_path_and_file}", true)
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
82
|
end
|
91
83
|
|
92
84
|
end
|
data/lib/core/vm.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class VM
|
4
|
+
|
5
|
+
def self.run_on_vm(script_name, args = [])
|
6
|
+
|
7
|
+
unless args.is_a? Array
|
8
|
+
raise RuntimeError, 'args (to run_on_vm) must be an Array'
|
9
|
+
end
|
10
|
+
|
11
|
+
script_name_vm = "#{App::Config.param(ConfigUnique::VM_USER)}-#{script_name}"
|
12
|
+
|
13
|
+
scripts = get_all_scripts.keys
|
14
|
+
unless scripts.include?(script_name)
|
15
|
+
App::Terminal::error("Script doesn't exist: #{App::Terminal::format_invalid(script_name)}", nil, true)
|
16
|
+
end
|
17
|
+
|
18
|
+
commands = [
|
19
|
+
"scp #{App::Enum::get_base_path}/vm-scripts/#{script_name} #{App::Config.param(ConfigUnique::VM_USER)}@#{App::Config.param(ConfigUnique::VM_IP)}:/tmp/#{script_name_vm}",
|
20
|
+
]
|
21
|
+
|
22
|
+
App::Terminal::command(commands, nil, false, false)
|
23
|
+
|
24
|
+
command("chmod 0755 /tmp/#{script_name_vm}")
|
25
|
+
command("/tmp/#{script_name_vm} #{args.join(' ')}")
|
26
|
+
command("rm /tmp/#{script_name_vm}")
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# Runs a series of commands on the VM.
|
31
|
+
# @return void
|
32
|
+
def self.command(commands, verbose = true)
|
33
|
+
unless commands.is_a?(Array)
|
34
|
+
commands = [commands]
|
35
|
+
end
|
36
|
+
if commands.any?
|
37
|
+
commands.each do |command|
|
38
|
+
if verbose
|
39
|
+
puts "\x1B[48;5;136m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{App::Terminal::format_command("#{command}")}"
|
40
|
+
end
|
41
|
+
system("sshpass -p#{App::Config.param(ConfigUnique::VM_USER)} ssh #{App::Config.param(ConfigUnique::VM_USER)}@#{App::Config.param(ConfigUnique::VM_IP)} -t \"#{command}\"")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Returns all script files as hash, IE: {'sql-updates' => '/Library/Ruby/Gems/2.0.0/gems/brightpearl-cli-1.4.0/vm-scripts/sql-updates.sh'}
|
49
|
+
# @return Hash
|
50
|
+
|
51
|
+
def self.get_all_scripts
|
52
|
+
return_hash = {}
|
53
|
+
all_scripts = App::UtilsFiles::get_files_in_dir("#{App::Enum::get_base_path}/vm-scripts")
|
54
|
+
all_scripts.each do |file|
|
55
|
+
return_hash[File.basename(file)] = file
|
56
|
+
end
|
57
|
+
return_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/lib/routes/dummy_order.rb
CHANGED
data/lib/routes/fix.rb
CHANGED
@@ -10,6 +10,9 @@ module AppCommand
|
|
10
10
|
@mysql_app = App::MySQL::vm
|
11
11
|
@mysql_ses = App::MySQL::vm('_session')
|
12
12
|
|
13
|
+
@sql_index_start = nil
|
14
|
+
@sql_index_end = nil
|
15
|
+
|
13
16
|
opts_validate
|
14
17
|
opts_routing
|
15
18
|
|
@@ -17,33 +20,55 @@ module AppCommand
|
|
17
20
|
|
18
21
|
def opts_validate
|
19
22
|
|
23
|
+
if @opts[:sql_updates]
|
24
|
+
unless @args.any?
|
25
|
+
App::Terminal::error('Must specify a SQL update to run from', "For example, if the #{App::Terminal::format_highlight('current update fail')} happened at #{App::Terminal::format_directory('0306.sql')}, type \xe2\x86\x92 #{App::Terminal::format_action('306')}", true)
|
26
|
+
end
|
27
|
+
if @args[0] =~ /\A0?\d{3}\z/i
|
28
|
+
@sql_index_start = @args[0].to_i
|
29
|
+
sql_files = App::UtilsFiles::get_files_in_dir("#{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)}/brightpearl/structure")
|
30
|
+
@sql_index_end = File.basename(sql_files[sql_files.length - 1], '.sql').to_i
|
31
|
+
if @sql_index_start > @sql_index_end
|
32
|
+
App::Terminal::error("Invalid SQL update index: #{App::Terminal::format_invalid(@args[0])}", "The most recent SQL update is currently: #{App::Terminal::format_directory("0#{@sql_index_end}.sql")}", true)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
App::Terminal::error("Invalid SQL update index: #{App::Terminal::format_invalid(@args[0])}", "The SQL update index you supplied does not match the required format (IE: #{App::Terminal::format_highlight('306')} or #{App::Terminal::format_highlight('0306')}).", true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
20
39
|
end
|
21
40
|
|
22
41
|
def opts_routing
|
23
42
|
|
24
|
-
if @opts[:
|
43
|
+
if @opts[:login_sessions]
|
25
44
|
clear_sessions
|
45
|
+
elsif @opts[:sql_updates]
|
46
|
+
sql_updates
|
26
47
|
else
|
27
48
|
system('bp f -h')
|
28
49
|
end
|
29
50
|
|
30
51
|
end
|
31
52
|
|
53
|
+
# Fixes problem with Login (when sessions get screwed up)
|
54
|
+
# @return void
|
32
55
|
def clear_sessions
|
33
56
|
App::Terminal::info('Attempting to clear all sessions from DB..')
|
34
|
-
|
35
57
|
App::Terminal::output('DELETE FROM _session.session;')
|
36
58
|
@mysql_ses.query('DELETE FROM session;')
|
37
|
-
|
38
59
|
App::Terminal::output('DELETE FROM app.session_to_licence_type;')
|
39
60
|
@mysql_app.query('DELETE FROM session_to_licence_type;')
|
40
|
-
|
41
61
|
App::Terminal::output('DELETE FROM app.sessions;')
|
42
62
|
@mysql_app.query('DELETE FROM sessions;')
|
43
|
-
|
44
63
|
puts
|
45
64
|
end
|
46
65
|
|
66
|
+
# Runs all SQL updates from a specified index
|
67
|
+
# @return void
|
68
|
+
def sql_updates
|
69
|
+
App::VM::run_on_vm('sql-updates.sh', [@sql_index_start, @sql_index_end + 1])
|
70
|
+
end
|
71
|
+
|
47
72
|
end
|
48
73
|
|
49
74
|
end
|