Labinvent nouvelle version

Version 56 (Alexandre Cases, 04/20/2016 02:20 pm) → Version 57/222 (Alexandre Cases, 04/20/2016 02:22 pm)

h1. Labinvent 2.0 (cakephp3)

{{toc}}

h2. RECUPERATION DU LOGICIEL

h3. Authenticate to https://gitlab.irap.omp.eu/epallier/labinvent

In order to get this software, you must first authenticate on the IRAP gitlab.

For this, just go to https://gitlab.irap.omp.eu/epallier/labinvent
and either sign in with your LDAP account (if you are from IRAP),
or register via the "Sign up" form (then, confirm your registration by answering an email sent by gitlab,
and wait for the "SI" to authorize your registration)

h3. Browse the code (from gitlab)

https://gitlab.irap.omp.eu/epallier/labinvent/tree/master

h3. Download it (static version, not synchronized)

You can download the current version of the software.

Go to https://gitlab.irap.omp.eu/epallier/labinvent/tree/master

Click on "Download zip" on the up right hand corner.

Double-click on it to unzip it.

You should get a "labinvent.git" folder.

In this documentation, this software folder will be referenced as "labinvent".

(you can rename "labinvent.git" as "labinvent" if you want : "mv labinvent.git labinvent")

h3. Get it from GIT (dynamic version, synchronized)

(If you are using Windows, you must first get the git software, see below "Get git for Windows")

By getting the software from git, you will get a dynamically synchronized version,
which means that you will be able to update your version as soon as a new version is available
(with the command : "git pull").

* From Eclipse : See below, section "NOTES FOR ECLIPSE USERS"

* From the terminal

<pre>
git clone https://gitlab.irap.omp.eu/epallier/labinvent.git labinvent
</pre>

_(or also : git clone git@gitlab.irap.omp.eu:epallier/labinvent.git labinvent)_

If you ever get this error message... :
<pre>
fatal: unable to access 'https://gitlab.irap.omp.eu/epallier/labinvent.git/': Peer's certificate issuer has been marked as not trusted by the user.
</pre>

...then, type this command (and then run again the "git clone" command):
<pre>
$ git config --global http.sslVerify false

Then check that your config is ok:

$ cat ~/.gitconfig
[user]
name = Etienne Pallier
email = epallier@irap.omp.eu
[http]
sslVerify = false
[push]
default = simple
</pre>

(Also, the first time you get the project, git will ask you for a login and password)

This creates a labinvent/ folder containing the project (with a .git/ subfolder for synchronization with the git repository)

h4. (Windows only) : Get git for Windows

* Download git at https://git-scm.com/download/win
* Run setup (keep default configurations)
* Once installed, open cmd
<pre>
$ git config --global http.sslVerify false
</pre>

You can now use your git from the cmd or the graphic client !

---

h2. INSTALLATION

h3. A/ PREREQUIS

Les commandes effectuer pour les prérequis ont été effectuer sur UBuntu 14.04.4

* Pour commencer il faut mettre à jour les "repository" de apt :
> sudo apt-get update && sudo apt-get upgrade

* Un serveur web (apache avec le mod_rewrite actif)
> sudo apt-get install apache2

> Editer le fichier /etc/apache2/apache2.conf et mettre le paramêtre "KeepAlive" à "Off" :
<pre>
KeepAlive Off
</pre>

> Par défaut Apache utilise un "event module" et PHP utilise un "prefork module" par défaut.
> Il faut désactiver le 1er module et activer le second :
> > sudo a2dismod mpm_event
> > sudo a2enmod mpm_prefork

> Vous pouvez redémarrer Apache :
> > sudo service apache2 restart

* Un serveur de base de données (MySQL)
> sudo apt-get install mysql-server

* PHP 5.5.9 ou plus
> sudo apt-get install php5 php-pear
> sudo apt-get install php5-mysql

> Dans le fichier /etc/php/apache2/php.ini, vous devez positionner votre répertoire de log :
<pre>
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log
max_input_time = 30
</pre>

> Ensuire il faut créer le dossier en question et donner au groupe d'apache (ici www-data) les droits sur ce dossier :
> > sudo mkdir /var/log/php
> > sudo chown www-data /var/log/php

> Vous pouvez recharger Apache :
> > sudo service apache2 reload

* Extension PHP "mbstring" et librairie "zlib"
> sudo apt-get install libapache2-mod-php5

* Extension PHP "intl"
> sudo apt-get install php5-intl

* Librairie PHP "php-gd"
> sudo apt-get install php5-gd
Quand "php-gd" est installé, aller dans le fichier /etc/php5/apache2/php.ini :
Vérifier que la ligne suivante est présente et décommentée (absence de ";" devant la ligne) sinon rajouter la :
<pre>
extension=gd.so
</pre>

* Pour vérifier la configuration d'apache et de ses modules :
> Il faut créer une page info.php dans le dossier public_html contenant les lignes suivantes :
<pre>
<?php
phpinfo();
?>
</pre>

> La page d'info devrait être accessible : http://localhost/info.php

* Il est aussi conseillé d'avoir un "phpmyadmin" installé pour pouvoir gérer manuellement la base de données.
>

* Après avoir installé tous les prérequis, récupérer l'archive "labinvent.tar.gz".

* Placer cette archive à l'endroit voulu, 2 possibilités :
- (1) soit vous placez cette archive directement dans le repertoire des sites webs du serveur web (par exemple /var/www/html/localhost/public_html/)
- (2) soit vous la placez n'importe où ailleurs (par exemple dans votre repertoire home), et ensuite vous indiquerez au serveur web où trouver ce projet

* Dézipper l'archive :
"tar xvfz labinvent.tar.gz"
> cela crée un dossier labinvent.git/

h3. B/ INSTALLATION

Nous vous préconisons d'installer le logiciel en mode "SANS LDAP", et d'activer le mode "AVEC LDAP" par la suite, si vous en avez besoin.

* Aller dans le repertoire d'installation :
cd labinvent/install/

* Exécuter le script d'installation :
./installation.sh
(vous pouvez le faire en tant qu'administrateur "root", mais ça n'est pas nécessaire, le script fera quelques petits "sudo" seulement quand nécessaire).
(Conseil : à la plupart des questions, laissez les réponses par défaut)
(Comme expliqué au début, faites une installation en mode "sans LDAP")

* Configuration BD
- Après avoir terminé le script d'installation, ouvrir le fichier ./config/app.php
- Aller à la section Datasources
- Modifier les attributs "host", "username", "password" et "database" pour qu'ils correspondent à votre base de données.

* Autoriser les fichiers .htaccess sur le site :
(cf http://book.cakephp.org/3.0/fr/installation.html#url-rewriting)

Dans le fichier apache2.conf de Apache, si vous avez déja quelque chose comme ceci, cela suffit :

> <Directory />
> Options FollowSymLinks
> AllowOverride All
> Order deny,allow
> Deny from all
> </Directory>

Sinon, vous pouvez ajouter ceci, uniquement pour Labinvent :

> <Directory /labinvent>
> Options FollowSymLinks
> AllowOverride All
> </Directory>

NB : si labinvent n'est pas dans le repertoire des sites webs, il faut mettre son chemin absolu a la place de /labinvent :
> <Directory /chemin/abosolu/vers/labinvent>

* Tester l'accès web à l'application : http://localhost/labinvent.git/

> Remarques :
> > Dans CakePHP3 un serveur de développement est disponible, il faut se placer à la racine du projet faire la commande "bin/cake server".
> > L'application devrait être accessible à l'adresse suivante par défaut : http://localhost:8765/

h2. (DEV ONLY) Installation from scratch (Sous UBuntu)

h3. Création projet avec Composer

* Télécharger composer.phar :
"curl -s https://getcomposer.org/installer | php"

* Avec le Composer créer un nouveau projet :
"php composer.phar create-project --prefer-dist cakephp/app labinvent_2.0"

> Voir structure projet : http://book.cakephp.org/3.0/fr/intro/cakephp-folder-structure.html

* On rempli la base de données avec le fichier sql

* On indique la BD utilisé à CakePHP dans le fichier config/app.php, propriété "Datasources".

* On se place à la racine du projet

* On génère le code Scaffold :
"bin/cake bake all nom_table" --> ça génére les modeles, les vues, et les controlleurs.

> Commande (en une fois) :
> > bin/cake bake all categories && bin/cake bake all emprunts && bin/cake bake all groupes_metiers && bin/cake bake all groupes_thematiques && bin/cake bake all organismes && bin/cake bake all sites && bin/cake bake all sous_categories && bin/cake bake all suivis && bin/cake bake all sur_categories && bin/cake bake all type_suivis && bin/cake bake all documents && bin/cake bake all utilisateurs && bin/cake bake all materiels

h3. Modification de la base de données
> Une version du sql corrigée au fur et à mesure est disponible dans le git :
> > Dans database/, le fichier labinvent_2.0_19-04-16 correspond à la création de la base.
> > Dans database/, le fichier labinvent_2.0_insert-irap_19-04-16 correspond aux insertions.

* Table "fichiers" en doublon de "documents" => supprimer
* Attribut organisme inutile dans la table matériel => supprimer

h3. Autres remarques lors du dévellopement



h4. installation.sh instalation.sh

* "phpqrcode" et "fpdf" dans dossier vendor

* CakePHP oblige à changer le grain de sel (security.salt) par rapport a la config par défaut

* Remplisage du fichier config app.php par l'utilisateur (BD, grain de sel, ...) ?

---



h2. (DEV ONLY) INSTALLATION DEPUIS ECLIPSE

1) Préparation d'Eclipse

Download Eclipse pour Php (plugin PDT déjà inclus) :
http://www.eclipse.org/downloads
(sinon, éventuellement http://www.eclipse.org/downloads/index-developer.php)
(on peut aussi télécharger un eclipse standard, et lui ajouter ensuite le plugin PDT)
Choisir "Eclipse for PHP Developpers"
Fin 2014, j'ai téléchargé la version Luna 4.4.1 SR1
Workspace proposé par défaut : /Users/pallier/Documents/workspace
(==> remplacé par /Users/pallier/projects/Eclipse/eclipse_luna_php_workspace)

Cliquer sur "Workbench"

Se placer dans la perspective PHP

Installer un client svn avec le plugin subversive :
Help/Eclipse Marketplace, chercher "subversive"
Installer Subversive (pour moi, c'était version 2.0.1)
Restart Eclipse

File/Import/From svn
==> demande à installer un connecteur svn
J'ai choisi le plus récent, soit "svn kit 1.8.7" (compatible avec svn 1.7 et 1.8)
(il contient Subversive svn connectors 4.1.2)

Restart Eclipse

2) Recupération du projet

File/Import/From svn (2ème fois)
URL : https://usvn-inventirap.irap.omp.eu/repo/inventirap/trunk
(répondre Non à la proposition de normaliser l'arborescence)
donner un nom, par exemple : labinvent2015
Utiliser emplacement :
- par défaut (directement dans le dossier d'Eclipse, c'est plus simple)
ou bien
- /Applications/XAMPP/xamppfiles/htdocs (si on veut que le projet s'execute directement dans le dossier web apache htdocs, mais ca n'est pas obligatoire...)

S'assurer que le projet est bien reconnu comme un projet PHP (il doit y avoir un petit "P" sur le dossier racine du projet)
Si ça n'est pas le cas, vérifier que le fichier .project (à la racine) contient bien
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
NB : Le fichier .project est normalement versionné et donc le projet labinvent devrait être reconnu automatiquement comme projet PHP

S'assurer que les fichiers de vue de cakephp (*.ctp) sont bien reconnus comme des fichiers PHP.
Pour tester cela, ouvrir le fichier de vue cakephp/app/View/Categories/get_all.ctp
Si ce fichier s'ouvre comme un simple fichier texte, c'est qu'il n'est pas reconnu par Eclipse comme un fichier Php.
Il faut donc associer l'editeur Php a l'extension de fichier "*.ctp" :
- Preferences/General/Content types
- Dans la liste "Content types", ouvrir la section "Text", selectionner PHP
- Ajouter l'extension "*.ctp"

Vérifier la version de php utilisée (il serait préférable d'utiliser la meme version que celle du serveur officiel, début 2015 c'est toujours php 5.3) :
- Clic-droit sur le projet, Propriétés
- PHP
- Interpreter
- Enable project specific settings, PHP Version : "PHP 5.3"

S'assurer que le texte est bien encodé en UTF-8 par défaut :
clic-droit sur le dossier racine du projet (dans PHP Explorer), Properties, Resource : dans la zone "Text file encoding" cocher "Other" et sélectionner UTF-8
(
Il faudrait commiter ça mais je ne sais pas trop si c'est risqué ou pas.
Les fichiers concernés sont :
- .project (déjà versionné) : car il commence par la ligne "<?xml version="1.0" encoding="UTF-8"?>"
- mais c'est surtout celui-ci qui compte (actuellement ignoré de svn) : .settings/org.eclipse.core.resources.prefs : car sa 2eme ligne est "encoding/<project>=UTF-8"
)

Les éléments suivants sont normalement DEJA ignorés par svn (svn:ignore), à vérifier :
- .settings/
- cakephp/app/tmp/ : tout sauf
- documents/
- cakephp/app/Config/ :
- database.php
- labinvent.php

*********************************************************
REMARQUES INTERRESSANTES (MAIS VOUS POUVEZ LES IGNORER)

// DEBUT DES REMARQUES

A la racine du projet, j'ai plusieurs éléments cachés de configuration Eclipse :

1) fichier .buildpath
Il est versionné puisque "svn status .buildpath" (depuis la console) ne donne rien
Il contient :

<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
<buildpathentry kind="lib" path="docs/mockup/mockup_html.zip"/>
<buildpathentry kind="src" path="cakephp"/>
</buildpath>

2) fichier .project
Il est déjà versionné
Il contient :
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>invirap</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

3) dossier .settings/ (exclus de svn)
Il contient 3 fichiers :

- org.eclipse.core.resources.prefs : bizarrement, il ne contient que quelques références seulement :
eclipse.preferences.version=1
encoding//cakephp/app/Controller/MaterielsController.php=UTF-8
encoding//cakephp/app/View/Elements/menu_view.ctp=UTF-8
encoding//cakephp/app/View/Layouts/default.ctp=UTF-8
encoding//cakephp/app/View/Materiels/index.ctp=UTF-8
encoding//cakephp/app/View/Materiels/scaffold.view.ctp=UTF-8
encoding//database/Upd_TableConstraints.sql=UTF-8
encoding//database/update/README.txt=UTF-8
encoding//docs/HOWTO.txt=UTF-8
encoding//install/HOWTO.txt=UTF-8
encoding/<project>=UTF-8

- org.eclipse.php.core.prefs
eclipse.preferences.version=1
include_path=0;/invirap\u00051;/invirap/docs/mockup/mockup_html.zip

- org.eclipse.wst.common.project.facet.core.xml : sans doute inutile ? (lié à "Faceted Project Validation Builder" dans Properties/Builders)
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="php.core.component"/>
<fixed facet="php.component"/>
<installed facet="php.core.component" version="1"/>
<installed facet="php.component" version="5.4"/>
</faceted-project>

// FIN DES REMARQUES
*********************************************************

II - Configuration du projet LABINVENT
**************************************************

Aller maintenant dans la section INSTALLATION ci-dessue, à partir du point "B/ Installation"

h2. %{margin-left:0px; font-weight:bold; font-size:25px; display:block; color:red;}(DEV ONLY) NOTES FOR ECLIPSE USERS%

0) Install Eclipse (if necessary)

Get the Eclipse version for Php

Install the plug-in pydev (via install new software, add http://pydev.org/updates)

Install the django template editor (via install new software, add http://eclipse.kacprzak.org/updates)

1) Deactivate CA certificate verification

Window -> Preferences -> Team -> git -> configuration -> Add entry

Key = http.sslVerify
Value = false

2) Fetch the project

File/Import project from git

Select repository source: Clone URI: https://gitlab.irap.omp.eu/epallier/labinvent.git

Directory:
par défaut, il propose : /Users/epallier/git/labinvent
mais on peut le mettre ailleurs (c'est ce que j'ai fait)

initial branch: master
remote name: origin

Import as general project

Project name: LABINVENT

3) Configure the project

The project is created. Now, you have to set it as a «PyDev » and a « Django » project.

clic droit sur le projet / PyDev / set as a PyDev project

4) Set Code style

Window/Preferences : Pydev / Editor
- Auto Imports : uncheck « Do auto import »
- Code style:
- Locals … : camelCase
- Methods : camelCase() with first lower
- Code style / Code Formatter: activer « use autopep8.py for code formatting »
- Tabs : Tab length : 4

5) Now, once the Python3 virtual environment is installed (see above),
set it in Eclipse as the project interpreter:

Right clic on the project / Properties / PyDev - Interpreter/Grammar :
Grammar version : 3

Interpreter : click on « click here to configure an interpreter not listed »

click on « New... » :
- Interpreter name : venv_py35_pyros
- Interpreter executable : click on « Browse »
Select your virtualenv python35 executable (private/venv_py35_pyros/bin/python3.5)
click OK

*Now, a last thing to do so that Pydev finds Django:*

In the Python interpreters list, select your virtual env (venv_py35_pyros)

Click on the tab "Libraries"

clic on 'New folder', then select your virtualenv's lib/python3.5/site-packages folder

OK

Interpreter: select now venv_py35_pyros from the list

OK

6) Test

* Right-clic on the project / Django / Run Django tests

* Right-clic on the project / Django / Custom command / ...

7) Run

Right clic on project -> Django/Custom command/runserver

Error on Ubuntu :

<pre>

Traceback (most recent call last):
File "/home/carens_p/git/pyros/src/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'

</pre>

Project -> Properties -> Pydev interpreter -> Clic here to configure an interpreter not listed

select venv_py35_pyros

In Libraries, clic on 'New folder', then select your virtualenv's lib/python3.5/site-packages folder.

OK -> re-select venv_py35_pyros in 'Interpreter' dropdown menu

Then right clic on project -> Django/Custom command/runserver

check http://localhost:8000/