Skip to content

Commit

Permalink
Fixes custom_field_choices dependent record updates. Fixes #521.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice TEXIER committed Apr 2, 2016
1 parent 3946e5d commit e5ecc2a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 71 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This installation method works with Debian-like OS (Debian, Ubuntu, Linux Mint..
* [English](https://github.com/ekylibre/ekylibre/blob/master/doc/guides/installation.rdoc) ([for Debian Jessie](https://github.com/ekylibre/ekylibre/blob/master/doc/guides/installation-debian-jessie.rdoc))
* [Français](https://wiki.ekylibre.com/fr/guides/installation)

Ekylibre depends on PostgreSQL (≥ 9.5) and PostGIS (≥ 2.2).

## Contributing

We encourage you to contribute to Ekylibre.
Expand Down
6 changes: 3 additions & 3 deletions app/models/custom_field_choice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class CustomFieldChoice < Ekylibre::Record::Base

before_update do
old = old_record
if self.value != old.value && custom_field.column_exists?
custom_field.customized_model.where(custom_field.column_name => old.value).update_all(custom_field.column_name => self.value)
if self.value != old.value
custom_field.customized_model.where("custom_fields->>'#{custom_field.column_name}' = ?", old.value).update_all("custom_fields = jsonb_set(custom_fields, '{#{custom_field.column_name}}', to_jsonb(#{self.class.connection.quote(self.value)}::VARCHAR))")
end
end

Expand All @@ -67,6 +67,6 @@ class CustomFieldChoice < Ekylibre::Record::Base

# Returns all linked records for the given model
def records
custom_field.customized_model.where(custom_field.column_name => self.value)
custom_field.customized_model.where("custom_fields->>'#{custom_field.column_name}' = ?", self.value)
end
end
16 changes: 11 additions & 5 deletions doc/guides/installation-debian-jessie.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ Architecture is assumed to be +amd64+. Replace it where it's necessary.

We assume that you are a valid sudoer. To get ready, add your account in +sudo+ group.

su
apt-get install sudo # if you don't know if sudo is installed
adduser bob sudo
su
apt-get install sudo # if you don't know if sudo is installed
adduser bob sudo

Logout and login and you can sudo.

== 1. Dependencies

Before all, install all distribution dependencies:
Before all, add PostgreSQL APT repository (See http://www.postgresql.org/download/linux/debian/ for more information):

sudo apt-get install imagemagick graphicsmagick tesseract-ocr tesseract-ocr-ara tesseract-ocr-jpn tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript openjdk-7-jdk libicu52 redis-server postgresql-9.4-postgis-2.1 postgresql-contrib libcurl4-openssl-dev openjdk-7-jdk libgeos-dev libgeos++-dev libproj-dev libpq-dev libxml2-dev libxslt1-dev zlib1g-dev libicu-dev libqtwebkit-dev
echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' | sudo tee --append /etc/apt/sources.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

Then, install all distribution dependencies:

sudo apt-get install imagemagick graphicsmagick tesseract-ocr tesseract-ocr-ara tesseract-ocr-jpn tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript openjdk-7-jdk libicu52 redis-server postgresql-9.5-postgis-2.2 postgresql-contrib-9.5 libcurl4-openssl-dev openjdk-7-jdk libgeos-dev libgeos++-dev libproj-dev libpq-dev libxml2-dev libxslt1-dev zlib1g-dev libicu-dev libqtwebkit-dev

== 2. Ruby

Expand Down
109 changes: 47 additions & 62 deletions doc/guides/installation.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,30 @@

This a short explanation on installation steps for developers.

If you are on Debian Jessie, please take a look at {detailed installation guide}[https://github.com/ekylibre/ekylibre/blob/master/doc/guides/installation-debian-jessie.rdoc].

== 1. Dependencies

* Before all, install all distribution dependencies:

sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 libpq-dev libqtwebkit-dev libmagic-dev libxml2-dev libxslt1-dev libgdal1-dev libjson0-dev zlib1g-dev build-essential wget openjdk-7-jdk graphicsmagick tesseract-ocr tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript libicu52 libcurl4-openssl-dev libicu-dev redis-server

* Install PostGIS (≥ 2.1) from source:
* Download and install Geos (≥ 3.4) from http://trac.osgeo.org/geos:
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar xjvf geos-3.4.2.tar.bz2
cd geos-3.4.2
./configure
make
sudo make install
Or in one line:
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2 && tar xjvf geos-3.4.2.tar.bz2 && cd geos-3.4.2 && ./configure && make && sudo make install
* Download and install Proj4 (≥ 4.8) from http://trac.osgeo.org/proj:
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar xzvf proj-4.8.0.tar.gz
cd proj-4.8.0
./configure
make
sudo make install
Or in one line:
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz && tar xzvf proj-4.8.0.tar.gz && cd proj-4.8.0 && ./configure && make && sudo make install
* Download and install PostGIS (≥ 2.1) from http://postgis.net:
wget http://download.osgeo.org/postgis/source/postgis-2.1.4.tar.gz
tar xzvf postgis-2.1.4.tar.gz
cd postgis-2.1.4
./configure
make
sudo make install
Or in one line:
wget http://download.osgeo.org/postgis/source/postgis-2.1.4.tar.gz && tar xzvf postgis-2.1.4.tar.gz && cd postgis-2.1.4 && ./configure && make && sudo make install

=== Ubuntu 14.04

You can install postgresql-9.3-postgis-2.1 and libgeos-dev packages to get all directly. But you need to ensure that libgeos.so exist, by default you'll need to link the existing lib:

ln -s /usr/lib/libgeos-3.4.2.so /usr/lib/libgeos.so
* Before all, install all database. See http://www.postgresql.org/download/ to install PostgreSQL on your system. PostgreSQL 9.5 is required at least with PostGIS 2.2 and PostgreSQL contrib for its +uuid-ossp+ extension.

* Then, install all dependencies. Command and package can differ between distributions or OS:

sudo apt-get imagemagick graphicsmagick tesseract-ocr tesseract-ocr-ara tesseract-ocr-jpn tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript openjdk-7-jdk libicu52 redis-server postgresql-9.5-postgis-2.2 postgresql-contrib-9.5 libcurl4-openssl-dev openjdk-7-jdk libgeos-dev libgeos++-dev libproj-dev libpq-dev libxml2-dev libxslt1-dev zlib1g-dev libicu-dev libqtwebkit-dev

== 2. Ruby

* Install Ruby 2.0 or later. If your distribution isn't up-to-date, see {RVM}[https://rvm.io] or {RbEnv}[https://github.com/sstephenson/rbenv] to install the good version, else:
sudo apt-get install ruby2.0 ruby2.0-dev ruby-dev
* Install Ruby 2.2 or later. If your distribution isn't up-to-date, see {RVM}[https://rvm.io] or {RbEnv}[https://github.com/sstephenson/rbenv] to install the good version.

Or compile it from source. In one line:
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz && tar xzvf ruby-2.0.0-p481.tar.gz && cd ruby-2.0.0-p481 && ./configure && make && sudo make install
== 3. Get sources

NOTE : we advise you to take the RBENV method
* Clone sources from repository
git clone https://github.com/ekylibre/ekylibre.git /path/to/ekylibre

== 3. Configuration
== 4. Configure Database

* Configure a DB superuser as default user in your +config/database.yml+.
In production mode, you'll need to use a normal user without SUPERUSER not CREATEDB right.

* Install bundler with rubygems:
gem install bundler

* Move to Ekylibre directory root and install gems with bundler:
cd /path/to/ekylibre
JAVA_HOME=/usr/lib/jvm/java-7-openjdk NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

Or you can add the following lines in your +~/.bash_profile+ in your home directory and run +bundle install+ after:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
export NOKOGIRI_USE_SYSTEM_LIBRARIES=1

* Create your +database.yml+ in +config/+

default: &default
Expand All @@ -86,16 +42,45 @@ You can install postgresql-9.3-postgis-2.1 and libgeos-dev packages to get all d
<<: *default
database: ekylibre_development

== 5. Configure ruby dependencies

* Install bundler with rubygems:
gem install bundler

* Move to Ekylibre directory root and install gems with bundler:
cd /path/to/ekylibre
JAVA_HOME=/usr/lib/jvm/java-7-openjdk NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

Or you can add the following lines in your +~/.bash_profile+ in your home directory and run +bundle install+ after:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
export NOKOGIRI_USE_SYSTEM_LIBRARIES=1


== 6. Initialize database

* Create and migrate database:
rake db:create db:migrate

* Optionally, it's possible to load anonymized data of a real (french polycultural-cattling) farm, just replace 'instance' by 'demo':
rake first_run max=50 name=instance
See {rails guide}[http://guides.rubyonrails.org/active_record_migrations.html#running-migrations] for more informations on migrations.

== 7. Create an empty farm

* Execute command:
rake tenant:init TENANT=my-little-farm

* Add in +/etc/hosts+ a line to configure an artificial subdomain corresponding to your instance:
echo '127.0.0.1 my-little-farm.ekylibre.lan' | sudo tee --append /etc/hosts

Optionally, it's possible to load anonymized data of a real (french polycultural-cattling) farm. Install data from https://github.com/ekylibre/first_run-demo in +/path/to/ekylibre/db/first_runs/demo+, and run:

rake first_run TENANT=demo

Don't forget to update your +/etc/hosts+ file.

* Add in +/etc/hosts+ a line to configure a factive subdomain corresponding to your instance:
127.0.0.1 instance.ekylibre.lan
== 8. Try it

* Launch server:
rails server
foreman start

* Open your web browser and go to http://instance.ekylibre.lan:3000
* Open your web browser and go to http://my-farm.ekylibre.lan:8080
2 changes: 1 addition & 1 deletion test/ci/before_install
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ sudo apt-cache search postgis
echo ""
echo "--------------------------------------------------------------------------------"
echo "Install packages:"
sudo apt-get install -qq libgeos-dev libgeos++-dev libproj-dev postgresql-9.4-postgis-2.1 graphicsmagick tesseract-ocr tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript postgresql-contrib-9.4
sudo apt-get install -qq libgeos-dev libgeos++-dev libproj-dev postgresql-9.5-postgis-2.2 graphicsmagick tesseract-ocr tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa pdftk libreoffice poppler-utils poppler-data ghostscript postgresql-contrib-9.5
# sudo apt-get install -qq qtbase5-dev qtdeclarative5-dev qt5-default qt5-qmake libqt5webkit5-dev libxcb-glx0-dev

0 comments on commit e5ecc2a

Please sign in to comment.