From a3bf9f6369cce5b682b07fbed5cbb918e1fdd605 Mon Sep 17 00:00:00 2001 From: Sasha Boginsky <41092741+sashadev-sky@users.noreply.github.com> Date: Mon, 11 Mar 2019 18:24:01 -0400 Subject: [PATCH] Upgrade to mySQL5.7, Ruby warning reductions, .md file updates (#355) * delete old rails configurations * update pr template * update readme and docker image name * add a mysql setup file * update broken recaptcha link * use File.exist? instead * bump mysql2 * control mysql2 gem * add custom rake test functions to provide option to suppress warnings * small edit to mysql.md * another one * add rake task for total tests * add a require for sass gem * update deprecated URI.encode * undo a comment on Rakefile I made * ensure consistency for rake task names * migrate rake tasks to new branch * update readme * update encoding method --- Gemfile | 4 +- Gemfile.lock | 8 +- MYSQL.md | 149 ++++++++++++++++++++++ PULL_REQUEST_TEMPLATE.md | 2 + README.md | 4 +- Rakefile | 3 +- app/controllers/application_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/map.rb | 6 +- app/models/user.rb | 2 +- app/models/warpable.rb | 4 +- config/boot.rb | 2 +- config/initializers/new_rails_defaults.rb | 17 --- docker-compose.yml | 2 +- lib/cartagen.rb | 3 +- lib/gdal.rb | 5 +- libmysqlclient.18.dylib | 1 + 17 files changed, 176 insertions(+), 40 deletions(-) create mode 100644 MYSQL.md delete mode 100644 config/initializers/new_rails_defaults.rb create mode 120000 libmysqlclient.18.dylib diff --git a/Gemfile b/Gemfile index 9c5d82a88..59e5abcbe 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem "friendly_id" # dependencies group :dependencies do - gem 'mysql2', '~> 0.3.20' + gem 'mysql2', '< 0.4' gem "geokit-rails", "1.1.4" gem "image_science", "1.2.6" gem "recaptcha", :require => "recaptcha/rails" @@ -31,7 +31,7 @@ group :dependencies do # asset pipelining gem "sprockets"#, "2.12.1" - gem "sass" + gem "sass", :require => 'sass' gem "autoprefixer-rails" gem "uglifier" diff --git a/Gemfile.lock b/Gemfile.lock index 8c16dde90..90cd66493 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GEM i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) arel (3.0.3) - autoprefixer-rails (9.4.7) + autoprefixer-rails (9.4.8) execjs aws-sdk (1.5.8) httparty (~> 0.7) @@ -160,7 +160,7 @@ GEM execjs (>= 0.3.0, < 3) uuidtools (2.1.5) will_paginate (3.1.6) - will_paginate-bootstrap (1.0.1) + will_paginate-bootstrap (1.0.2) will_paginate (>= 3.0.3) PLATFORMS @@ -174,7 +174,7 @@ DEPENDENCIES geokit-rails (= 1.1.4) image_science (= 1.2.6) jshintrb - mysql2 (~> 0.3.20) + mysql2 (< 0.4) oa-openid (= 0.3.2) open_id_authentication paperclip (~> 4.2.2) @@ -198,4 +198,4 @@ RUBY VERSION ruby 2.4.4p296 BUNDLED WITH - 1.16.2 + 1.17.1 diff --git a/MYSQL.md b/MYSQL.md new file mode 100644 index 000000000..711b3f960 --- /dev/null +++ b/MYSQL.md @@ -0,0 +1,149 @@ +# installation troubleshooting & instructions + +## System Agnostic + +- bundler skipping over **mysql2** gem? + +```Bash + +$ rm .bundle/config + +$ bundle exec bundle install + +``` + + + +## MacOS + +**Homebrew setup:** + +(Note: alternative to Homebrew is [mySQL community server](https://dev.mysql.com/downloads/mysql/5.7.html#downloads) - available for all systems) + +Dependencies: + +- `cmake` + +- `openssl` + +```Bash + +$ brew install cmake + +$ brew install openssl + +``` + +Installation: + +```Bash + +#make sure you don't have any other versions of mysql installed +$ brew list + +#if you do +$ brew uninstall +$ brew unlink + +#install 5.7 +$ brew install mysql@5.7 + +$ brew link mysql@5.7 --force +``` + +Test Usage: + +```Bash + +# install brew services +$ brew tap homebrew/services + +# cmd to run always - suggest aliasing this in your bash profile +$ brew services start mysql@5.7 + +#confirm its running +$ brew services list + +# cmd to stop running +$ brew services stop mysql@5.7 + +``` + +Update Permissions + +```Bash +# check for right permissions to the PIDs +$ ls -laF /usr/local/var/mysql/ + +# if the owner is root you should change it to mysql or username +$ sudo chown -R /usr/local/var/mysql/ + +# confirm updated permissions +$ ls -laF /usr/local/var/mysql/ + +``` + +Account Setup + +```Bash +# secure your account +$ mysql_secure_installation + +# set password +$ mysqladmin -u root password +# login -- not root anymore +$ mysql -u -p + +``` + +Permission issues above? + +(note these commands also fix the error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)) + +```Bash + +$ mysql.server stop + +#unset the temporary directory +$ echo $TMPDIR +$ unset TMPDIR +$ echo $TMPDIR + +$ whoami + +$ mysqld -initialize --verbose --user=$(whoami) --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp + +#restart mysql +$ mysql.server restart + + +$ mysql -u root + +#You should now be in the mysql command line shell +mysql> SELECT User, Host, authentication_string FROM mysql.user; + +mysql> rename user 'root'@'localhost' to ''@'localhost'; + +#confirm +mysql> SELECT User, Host, authentication_string FROM mysql.user; + +mysql> flush privileges; + +mysql> exit + +``` + +Reconfirm Access + +(whenever want to access the mysql db locally, need to run this login first - suggest aliasing in bash profile) + +```Bash + +$ mysql -u -p + +``` + + + +## Pending: please add instructions for your respective system + diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 9e326e5bd..0198120c9 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,5 @@ +References \#0000 (\<=== Add issue number here) + Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks! * [ ] tests pass -- `rake test` diff --git a/README.md b/README.md index b6da44829..6909011dd 100644 --- a/README.md +++ b/README.md @@ -88,14 +88,14 @@ Once NPM is installed, you should be able to run: ## Installation -You'll need at least Ruby v1.9.3 (**v2.1.x** preferred) +You'll need Ruby v2.4.4 (use your local ruby version management system - RVM / rbenv / etc. - to install and set locally) 1. Download a copy of the source with `git clone https://github.com/publiclab/mapknitter.git` 2. Install gems with `bundle install` from the rails root folder. You may need to run `bundle update` if you have older gems in your environment. 3. Copy and configure config/database.yml from config/database.yml.example, using a new empty database you've created 4. Copy and configure config/config.yml from config/config.yml.example (for now, this is only for the [Google Maps API Key, which is optional](http://stackoverflow.com/questions/2769148/whats-the-api-key-for-in-google-maps-api-v3)) 5. Initialize database with `bundle exec rake db:setup` -6. Enter ReCaptcha public and private keys in config/initializers/recaptcha.rb, copied from recaptcha.rb.example. To get keys, visit https://google.com/recaptcha/admin +6. Enter ReCaptcha public and private keys in config/initializers/recaptcha.rb, copied from recaptcha.rb.example. To get keys, visit https://www.google.com/recaptcha/admin/create 7. Install static assets (like external javascript libraries, fonts) with `bower install` 8. Start rails with `bundle exec passenger start` from the Rails root and open http://localhost:3000 in a web browser. (For some, just `passenger start` will work; adding `bundle exec` ensures you're using the version of passenger you just installed with Bundler.) diff --git a/Rakefile b/Rakefile index 8708a7df0..b6446b5e1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,6 @@ #!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. - require File.expand_path('../config/application', __FILE__) -Mapknitter::Application.load_tasks +Mapknitter::Application.load_tasks \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d81450d1f..af72c8d3e 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -34,7 +34,7 @@ def require_login unless logged_in? path_info = request.env['PATH_INFO'] flash[:warning] = "You must be logged in to access this section" - redirect_to '/login?back_to=' + URI.encode(path_info) # halts request cycle + redirect_to '/login?back_to=' + path_info.to_param # halts request cycle end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c4790d45d..2122d43c4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -47,6 +47,6 @@ def csrf_meta_tags out % [ Rack::Utils.escape_html(request_forgery_protection_token), Rack::Utils.escape_html(form_authenticity_token) ] end - end + end end diff --git a/app/models/map.rb b/app/models/map.rb index 398a0dff3..a55e6a8ea 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -163,8 +163,8 @@ def average_cm_per_pixel res = 1 if res == 0 # let's not ever try to go for infinite resolution scales << res unless res == nil end - sum = (scales.inject {|sum, n| sum + n }) if scales - average = sum/count if sum + total_sum = (scales.inject {|sum, n| sum + n }) if scales + average = total_sum/count if total_sum average else 0 @@ -384,7 +384,7 @@ def has_tag(tagname) def add_tag(tagname, user) tagname = tagname.downcase unless self.has_tag(tagname) - tag = self.tags.create({ + self.tags.create({ :name => tagname, :user_id => user.id, :map_id => self.id diff --git a/app/models/user.rb b/app/models/user.rb index 1fb0572f6..0c7d0b952 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,7 +42,7 @@ def email=(value) end def last_action - map = self.maps.order('updated_at DESC').limit(1).first.updated_at + self.maps.order('updated_at DESC').limit(1).first.updated_at end # Permissions for editing and deleting resources diff --git a/app/models/warpable.rb b/app/models/warpable.rb index cb5da2182..82c77eb44 100755 --- a/app/models/warpable.rb +++ b/app/models/warpable.rb @@ -148,11 +148,11 @@ def generate_perspectival_distort(pxperm,path) # everything in -working/ can be deleted; # this is just so we can use the files locally outside of s3 working_directory = self.working_directory(path) - Dir.mkdir(working_directory) unless (File.exists?(working_directory) && File.directory?(working_directory)) + Dir.mkdir(working_directory) unless (File.exist?(working_directory) && File.directory?(working_directory)) local_location = working_directory+self.id.to_s+'-'+self.image_file_name.to_s directory = self.warps_directory(path) - Dir.mkdir(directory) unless (File.exists?(directory) && File.directory?(directory)) + Dir.mkdir(directory) unless (File.exist?(directory) && File.directory?(directory)) completed_local_location = directory+self.id.to_s+'.png' # everything -masked.png can be deleted diff --git a/config/boot.rb b/config/boot.rb index 4489e5868..f2830ae31 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,4 +3,4 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/initializers/new_rails_defaults.rb b/config/initializers/new_rails_defaults.rb deleted file mode 100644 index 78e0117cc..000000000 --- a/config/initializers/new_rails_defaults.rb +++ /dev/null @@ -1,17 +0,0 @@ -# These settings change the behavior of Rails 2 apps and will be defaults -# for Rails 3. You can remove this initializer when Rails 3 is released. - -if defined?(ActiveRecord) - # Include Active Record class name as root for JSON serialized output. - ActiveRecord::Base.include_root_in_json = true - - # Store the full class name (including module namespace) in STI type column. - ActiveRecord::Base.store_full_sti_class = true -end - -# Use ISO 8601 format for JSON serialized times and dates. -ActiveSupport.use_standard_json_time_format = true - -# Don't escape HTML entities in JSON, leave that for the #json_escape helper. -# if you're including raw json in an HTML page. -ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0bef45e1e..4ac38994c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ db: - image: mysql:5.6 + image: mysql:5.7 environment: - MYSQL_DATABASE=mapknitter - MYSQL_USER=mapknitter diff --git a/lib/cartagen.rb b/lib/cartagen.rb index c910831c6..fd5496a92 100644 --- a/lib/cartagen.rb +++ b/lib/cartagen.rb @@ -20,7 +20,7 @@ def self.spherical_mercator_lat_to_y(lat,scale=10000) y * scale / 180 end - def self.spherical_mercator_y_to_lat(y,scale=10000) + def self.spherical_mercator_y_to_lat(y,scale=10000) #180/Math::PI * (2 * Math.atan(Math.exp(y/scale_factor*Math::PI/180)) - Math::PI/2) lat = (y / scale) * 180 180/Math::PI * (2 * Math.atan(Math.exp(lat * Math::PI / 180)) - Math::PI / 2) @@ -29,6 +29,7 @@ def self.spherical_mercator_y_to_lat(y,scale=10000) # collects coastline ways into collected_way relations; # see http://wiki.openstreetmap.org/wiki/Relations/Proposed/Collected_Ways def self.collect_ways(features) + # collected_ways variable unused review this function collected_ways = [] nodes = {} features['osm']['node'].each do |node| diff --git a/lib/gdal.rb b/lib/gdal.rb index d7b50b247..92109f803 100755 --- a/lib/gdal.rb +++ b/lib/gdal.rb @@ -9,10 +9,11 @@ def self.ulimit end def self.raw(cmd,verbose) + # unused variable stdin review this function stdin, stdout, stderr = Open3.popen3(self.ulimit+cmd) if verbose - puts stderr.readlines - puts stdout.readlines + puts stderr.readlines + puts stdout.readlines end end diff --git a/libmysqlclient.18.dylib b/libmysqlclient.18.dylib new file mode 120000 index 000000000..a488c8c50 --- /dev/null +++ b/libmysqlclient.18.dylib @@ -0,0 +1 @@ +/usr/local/mysql/lib/libmysqlclient.18.dylib \ No newline at end of file