Commit 36fed3f8 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

Comptoir v2.10.0

parents 022b8f63 69a4816e
Pipeline #18272 failed with stage
in 1 minute and 34 seconds
......@@ -5,7 +5,18 @@ Tous les changements notables de ce projet sont documentés dans ce fichier.
Le format s'appuie sur [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
et le projet suit [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 2.9.3 - 2021-04-06
## [2.10.0](https://gitlab.adullact.net/Comptoir/Comptoir-srv/tags/v2.10.0) - 2021-08-13
### Added
- [!544](https://gitlab.adullact.net/Comptoir/Comptoir-srv/-/merge_requests/544) Ajout d'un export JSON
### Fixed
- [!543](https://gitlab.adullact.net/Comptoir/Comptoir-srv/-/merge_requests/543) Correction du script d'import du SILL
## [2.9.3](https://gitlab.adullact.net/Comptoir/Comptoir-srv/tags/v2.9.3) - 2021-04-06
### Fixed
......
......@@ -18,22 +18,23 @@ $url = "https://raw.githubusercontent.com/DISIC/sill/master/2020/sill-2020.csv";
$fileName = 'SILL_2020.csv';
$dataSrc = file_get_contents($url);
file_put_contents($fileName, $dataSrc); /* [0] => ID
[1] => nom
[2] => fonction
[3] => annees
[4] => statut
[5] => parent
[6] => public
[7] => similaire-a
[8] => wikidata
[9] => comptoir-du-libre
[10] => licence */
[1] => nom
[2] => fonction
[3] => annees
[4] => statut
[5] => parent
[6] => public
[7] => support
[8] => similaire-a
[9] => wikidata
[10] => comptoir-du-libre
[11] => licence */
// column numbers of the csv file
$numberOfFileFields = 16;
$numberOfFileFields = 17;
$colYears = 3;
$colWikidata = 8;
$colComptoir = 9;
$colWikidata = 9;
$colComptoir = 10;
// file processing
$row = 1;
......@@ -68,8 +69,11 @@ if (($handle = fopen($fileName, "r")) !== false) {
$idWikidata = $data[$colWikidata];
$lineYears = explode(';', $data[$colYears]);
foreach ($lineYears as $year) {
$year = (int) trim($year);
$years[$year][$idComptoir] = $idWikidata;
$year = trim($year);
if ($year !== '') {
$year = (int) $year;
$years[$year][$idComptoir] = $idWikidata;
}
}
} else {
$noIds[$row] = $data;
......@@ -100,6 +104,7 @@ echo "\n------> ". ($row - 1) . " src";
echo "\n------> ". (count($noIds) - 1). " NO id comptoir";
foreach ($years as $year => $Ids) {
echo "\n------> ". count($Ids) . " software for SILL-$year";
// print_r($Ids);
}
echo "\n\n";
......
# How to upgrade from v2.9.3 to v2.10.0
## 1) First backup (DB + images files)
```bash
# (1) user comptoir
sudo su comptoir
# First backup (DB + images files)
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_data_AND_images.sh
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_structure_only.sh
ls -lh /home/comptoir/Comptoir-EXPORT/
```
## 2) Preloading vendor directory
```bash
# (1) use the user "comptoir"
sudo su comptoir
# Preloading vendor
mkdir /home/comptoir/tmp_migration
cd /home/comptoir/tmp_migration
git clone https://gitlab.adullact.net/Comptoir/Comptoir-srv.git
mv Comptoir-srv/ Comptoir_tmp_update_vendor
cd Comptoir_tmp_update_vendor/
git checkout origin/master
git log --decorate --oneline --graph --all
composer check-platform-reqs
composer validate
composer install
```
## 3) Activate maintenance site
see:
[www-maintenance-comptoir](https://gitlab.adullact.net/Adullact-prive/comptoir-prive/www-maintenance-comptoir)
(private repository)
```bash
# (1) use your user
# Activate maintenance site
sudo a2dissite 25-https_comptoir-du-libre.org.conf
sudo a2ensite 30-503-MAINTENANCE_https_comptoir-du-libre.org.conf
sudo service apache2 reload
# on your computer, the following command lines
# must retrun an HTTP 500 response
curl -v https://comptoir-du-libre.org/
curl -v https://comptoir-du-libre.org/notFoundPage
```
## 4) Backup before migration (DB + images files + main directory)
```bash
# (1) user comptoir
sudo su comptoir
# Second backup (DB + images files)
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_data_AND_images.sh
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_structure_only.sh
ls -lh /home/comptoir/Comptoir-EXPORT/
# Backup main directory
cd /home/comptoir/
DATE=$(date +"%Y.%m.%d_%Hh%M")
tar -czvf "Comptoir-srv_BACKUP_${DATE}.tar.gz" Comptoir-srv
```
## 5) Update source code
```bash
# (1) user comptoir
sudo su comptoir
# Update source code
cd /home/comptoir/Comptoir-srv
rm -rvf vendor/
git remote -v
git remote update -p
git checkout origin/master
git log --decorate --oneline --graph --all
```
## 6) Update vendor directory + clean cache
```bash
# (1) user comptoir
sudo su comptoir
# Update vendor directory (see step 2 "Preloading vendor directory")
cd /home/comptoir/Comptoir-srv
rm -rvf vendor/
mv -v ../tmp_migration/Comptoir_tmp_update_vendor/vendor ./
# Clean cache
cd /home/comptoir/Comptoir-srv
bin/cake cache clear_all
```
## 7) Apply migration of the database (new tables, adding fields, ...)
The following changes must be recorded in the [production version tracking](https://gitlab.adullact.net/Adullact-prive/comptoir-prive/Exploitation-Comptoir/-/blob/master/Suivi-versions-PROD.md) file.
```bash
# (1) user comptoir
sudo su comptoir
# Apply migration of the database (new tables, adding fields, ...)
cd /home/comptoir/Comptoir-srv
bin/cake migrations migrate
# Now you can apply additional changes in SQL with pgsl
# ---> nothing to do here for this version
```
## 8) Update config files
The following changes must be recorded in the [production version tracking](https://gitlab.adullact.net/Adullact-prive/comptoir-prive/Exploitation-Comptoir/-/blob/master/Suivi-versions-PROD.md) file.
nothing to do here for this version
```bash
# (1) user comptoir
sudo su comptoir
# Apply additional changes in config files
cd /home/comptoir/Comptoir-srv
vim config/comptoir.php # ---> nothing to do here for this version
vim config/app.php # ---> nothing to do here for this version
```
## 9) Enable the main website
see:
[www-maintenance-comptoir](https://gitlab.adullact.net/Adullact-prive/comptoir-prive/www-maintenance-comptoir)
(private repository)
```bash
# (1) use your user
# Enable the main website
sudo a2dissite 30-503-MAINTENANCE_https_comptoir-du-libre.org.conf
sudo a2ensite 25-https_comptoir-du-libre.org.conf
sudo service apache2 reload
# on your computer, the first following command line
# must return an HTTP 200 response code
# and the second return an HTTP 404 response code.
curl -v https://comptoir-du-libre.org/
curl -v https://comptoir-du-libre.org/notFoundPage
```
## 10) Backup after upgraded
```bash
# (1) user comptoir
sudo su comptoir
# Backup after upgraded (DB + images files)
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_data_AND_images.sh
/home/comptoir/Comptoir-srv/bin/COMPTOIR_export_DB_structure_only.sh
ls -lh /home/comptoir/Comptoir-EXPORT/
```
## 11) Clean up
```bash
# (1) user comptoir
sudo su comptoir
# Clean up
cd /home/comptoir/
rm -rvf tmp_migration/
rm -v Comptoir-srv_BACKUP_*.tar.gz
```
......@@ -293,7 +293,7 @@ Configure::write(
Configure::write(
'VERSION',
[
"footer" => "v2.9.3"
"footer" => "v2.10.0"
]
);
......
......@@ -169,8 +169,6 @@ $basicRoutes = function (RouteBuilder $routes) {
]
);
// Software ===============================================================
$routes->resources(
'Softwares',
......@@ -241,6 +239,10 @@ $basicRoutes = function (RouteBuilder $routes) {
"index/" => [
'action' => 'index',
'method' => ['GET'],
],
"export" => [
'action' => 'export',
'method' => ['GET'],
]
]
]
......
......@@ -86,6 +86,7 @@ class SoftwaresController extends AppController
if ($this->request->is('get')) {
$this->Auth->allow(
[
'export',
'index',
'add',
'view',
......@@ -230,6 +231,171 @@ class SoftwaresController extends AppController
$this->setBreadcrumbs();
}
/**
* Export method
*
* @return void
*/
public function export()
{
$this->request->allowMethod(['get']);
////////////////////////////////////////////////////////////
// Retrieve data from database
////////////////////////////////////////////////////////////
$this->paginate = [
"Softwares" => [
'sortWhitelist' => [
'softwarename',
'average_review',
'created',
'modified',
],
'limit' => Configure::read('LIMIT'),
'maxLimit' => Configure::read('LIMIT'),
'order' => ['softwarename' => Configure::read('ORDER')],
'contain' => [
'Reviews',
'Licenses',
'Tags',
'Userssoftwares' => [
'strategy' => 'select',
'queryBuilder' => function ($q) {
return $q->order(['Users.username' => 'ASC']);
},
'Users' => [
'fields' => [
'id',
'username',
'url'
]
]
],
'Providerssoftwares' => [
'strategy' => 'select',
'queryBuilder' => function ($q) {
return $q->order(['Users.username' => 'ASC']);
},
'Users' => [
'fields' => [
'id',
'username',
'url'
]
]
],
],
],
'contain' => ['Tags']
];
$softwares = $this->Softwares
->find(
'search',
[
'search' => $this->request->data,
"contain" => [
"Reviews",
"Licenses"],
]
)
->select(
[
'average_review' => $this->Softwares
->query()
->func()
->coalesce(
[
$this->Softwares->query()
->func()
->avg('Reviews.evaluation'),
0
]
)
]
)
// allow to sort by the virtual property "Average"
->leftJoinWith('Reviews')
->leftJoinWith('Licenses')
->group(['Softwares.id'])
->autoFields(true);
////////////////////////////////////////////////////////////
// Generate JSON export
////////////////////////////////////////////////////////////
$data = [
'date_of_export' => date(DATE_ATOM),
'number_of_software' => $softwares->count(),
'softwares' => []
];
foreach ($this->paginate($softwares) as $software) {
$providers = [];
# @TODO bug $provider->created
foreach ($software->providerssoftwares as $provider) {
$providers[] = [
'id' => $provider->user_id,
// 'created' => $provider->created,
// 'modified' => $provider->modified,
'url' => 'https://comptoir-du-libre.org/fr/users/'. $provider->user_id,
'name' => $provider->user->username,
'type' => $provider->user->user_type->name,
'external_resources' => [
'website' => $provider->user->url,
],
];
}
$users = [];
# @TODO bug $user->createdd
foreach ($software->userssoftwares as $user) {
if ($user->user->user_type->name === 'Administration') {
$users[] = [
'id' => $user->user_id,
// 'created' => $user->created,
// 'modified' => $user->modified,
'url' => 'https://comptoir-du-libre.org/fr/users/'. $user->user_id,
'name' => $user->user->username,
'type' => $user->user->user_type->name,
'external_resources' => [
'website' => $user->user->url,
],
];
}
}
$licenceName = '';
if (is_object($software->license)) {
$licenceName = $software->license->name;
}
$item = [
'id' => $software->id,
'created' => $software->created,
'modified' => $software->modified,
'url' => 'https://comptoir-du-libre.org/fr/softwares/'. $software->id,
'name' => $software->softwarename,
'licence' => $licenceName,
'external_resources' => [
'website' => $software->url_website,
'repository' => $software->url_repository,
],
'providers' => $providers,
'users' => $users,
];
$data['softwares'][] = $item;
}
$json = \json_encode($data, JSON_PRETTY_PRINT);
$exportPath = 'public/export/';
$exportFile = $exportPath . "comptoir-du-libre_export_v1.json";
if (is_dir(WWW_ROOT . $exportPath)) {
file_put_contents(WWW_ROOT . $exportFile, "$json");
$this->set('exportFile', "$exportFile");
$this->set('export', file_get_contents(WWW_ROOT . $exportFile));
}
}
/**
* View method
*
......
<?php
$this->layout = 'base';
$this->assign('title', __d("Softwares",'Softwares.index.title'));
// View debug json only for connected user with role = admin
if ($this->request->session()->read('Auth.User.role') === 'admin' ) {
if(isset($export) && isset($exportFile)) {
echo "<h1 id=\"export-json_displayed\">JSON export</h1>";
echo "<a id=\"link_export-json_displayed\" href=\"/$exportFile\">JSON export</a><hr>";
echo "<pre>$export</pre><hr>";
}
else {
echo "<h1 id=\"error_export-json_displayed\">Error: JSON export not available</h1>";
}
}
else {
if(isset($export) && isset($exportFile)) {
echo '<div id="export-json_not-displayed"></div>';
}
else {
echo '<div id="error_export-json_not-displayed"></div>';
}
}
?>
......@@ -263,4 +263,26 @@ class RoleAdminCheckActionsCest
$I->seeElement("//input[@id='photo']");
$I->seeElement("//textarea[@id='description']");
}
/**
* When trying to update JSON export
* verify that we can see link to export (because we have "admin" role)
*
* @group admin
* @group security
* @group export
* @param AcceptanceTester $I codeception variable
*
* @return void
*/
public function displayExportJson(AcceptanceTester $I)
{
$I->amOnPage('/softwares/export'); // Generate export
$I->seeElement("//h1[@id='export-json_displayed']");
$I->seeElement("//a[@id='link_export-json_displayed']");
$I->dontSeeElement("//h1[@id='error_export-json_displayed']");
$I->dontSeeElement("//div[@id='export-json_not-displayed']");
$I->dontSeeElement("//div[@id='error_export-json_not-displayed']");
}
}
......@@ -471,4 +471,25 @@ class UserAdministrationCheckActionsCest
$I->seeElement('div.message.error');
$I->see('You are not allowed to do that');
}
/**
* When trying to update JSON export
* verify that we can't see link to export (only user with "admin" role can see it)
*
* @group security
* @group export
* @param AcceptanceTester $I codeception variable
*
* @return void
*/
public function displayExportJson(AcceptanceTester $I)
{
$I->amOnPage('/softwares/export'); // Generate export
$I->dontSeeElement("//h1[@id='export-json_displayed']");
$I->dontSeeElement("//a[@id='link_export-json_displayed']");
$I->dontSeeElement("//h1[@id='error_export-json_displayed']");
$I->seeElement("//div[@id='export-json_not-displayed']");
$I->dontSeeElement("//div[@id='error_export-json_not-displayed']");
}
}
......@@ -58,4 +58,25 @@ class UserAnonymousCheckActionsCest
$I->click('//*[@id="btn_Softwares-usersSoftware-163"]'); // button : 'Se déclarer utilisateur'
$I->seeInCurrentUrl("/$lang/users/login");
}
/**
* When trying to update JSON export
* verify that we can't see link to export (only user with "admin" role can see it)
*
* @group admin
* @group export
* @param AcceptanceTester $I codeception variable
*
* @return void
*/
public function displayExportJson(AcceptanceTester $I)
{
$I->amOnPage('/softwares/export'); // Generate export
$I->dontSeeElement("//h1[@id='export-json_displayed']");
$I->dontSeeElement("//a[@id='link_export-json_displayed']");
$I->dontSeeElement("//h1[@id='error_export-json_displayed']");
$I->seeElement("//div[@id='export-json_not-displayed']");
$I->dontSeeElement("//div[@id='error_export-json_not-displayed']");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment