Class: Brightpearl::MySQL
- Inherits:
-
Object
- Object
- Brightpearl::MySQL
- Defined in:
- lib/core/mysql.rb
Constant Summary collapse
- DEFAULT_VM_SCHEMA =
'app'- DEFAULT_EC2_SCHEMA =
'brightpearl'
Class Method Summary collapse
- .ec2(schema = DEFAULT_EC2_SCHEMA) ⇒ Object
- .get_random_customer_id ⇒ Object
- .get_random_shipping_id ⇒ Object
- .vm(schema = DEFAULT_VM_SCHEMA) ⇒ Object
Class Method Details
.ec2(schema = DEFAULT_EC2_SCHEMA) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/core/mysql.rb', line 30 def self.ec2(schema = DEFAULT_EC2_SCHEMA) if @ec2_connection.nil? encrypter = Encrypter.new host = Brightpearl::Config.param(Brightpearl::Config::EC2_HOST) user = Brightpearl::Config.param(Brightpearl::Config::EC2_USER) pass = Brightpearl::Config.param(Brightpearl::Config::EC2_PASS) if host.nil? || user.nil? || pass.nil? || host == '' || user == '' || pass == '' Brightpearl::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 #{Brightpearl::Terminal::format_highlight('access data')}.", "Please speak to #{Brightpearl::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true) end @ec2_connection = Mysql.new( encrypter.decrypt(host), encrypter.decrypt(user), encrypter.decrypt(pass), schema ) end @ec2_connection end |
.get_random_customer_id ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/core/mysql.rb', line 52 def self.get_random_customer_id unless @ids_customers.any? customers = Brightpearl::MySQL::vm.query('SELECT customers_id FROM customers ORDER BY customers_id DESC LIMIT 100') customers.each_hash do |row| @ids_customers << row['customers_id'] end end @ids_customers.sample end |
.get_random_shipping_id ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/core/mysql.rb', line 62 def self.get_random_shipping_id unless @ids_shipping.any? ship_methods = Brightpearl::MySQL::vm.query('SELECT ship_method_id FROM ship_methods ORDER BY ship_method_id DESC LIMIT 100') ship_methods.each_hash do |row| @ids_shipping << row['ship_method_id'] end end @ids_shipping.sample end |
.vm(schema = DEFAULT_VM_SCHEMA) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/core/mysql.rb', line 16 def self.vm(schema = DEFAULT_VM_SCHEMA) if @vm_connection.nil? @vm_connection = Mysql.new( Brightpearl::Config.param(Brightpearl::Config::VM_IP), Brightpearl::Config.param(Brightpearl::Config::VM_MYSQL_USER), Brightpearl::Config.param(Brightpearl::Config::VM_MYSQL_PASSWORD), schema ) end @vm_connection end |