database files updated

parent d98cdfef
...@@ -8,7 +8,7 @@ STU_LOGIN_VALIDS=`egrep "\/stu\/login" access.json | grep "'status': 200" | wc - ...@@ -8,7 +8,7 @@ STU_LOGIN_VALIDS=`egrep "\/stu\/login" access.json | grep "'status': 200" | wc -
SHOW_GRIDS=`egrep "/stu/[0-9]+/grids" access.json | wc -l` SHOW_GRIDS=`egrep "/stu/[0-9]+/grids" access.json | wc -l`
STUDENTS_ACCESSED=`egrep "/stu/[0-9]+/grids" access.json | sed "s/.*\/stu\/\([0-9]\+\)\/.*/\1/g"|uniq |wc -l` STUDENTS_ACCESSED=`egrep "/stu/[0-9]+/grids" access.json | sed "s/.*\/stu\/\([0-9]\+\)\/.*/\1/g"|uniq |wc -l`
mail amontejo@ujaen.es <<END sendmail amontejo@ujaen.es <<END
Subject: Informe de Pictogram sobre $HOSTNAME Subject: Informe de Pictogram sobre $HOSTNAME
Nº de intentos de login de supervisor: $SUP_LOGIN_ATTEMPTS Nº de intentos de login de supervisor: $SUP_LOGIN_ATTEMPTS
Nº de logins válidos de supervisor: $SUP_LOGIN_VALIDS Nº de logins válidos de supervisor: $SUP_LOGIN_VALIDS
......
--- --------------------------------------------------------------------------- SET FOREIGN_KEY_CHECKS = 0;
---
--- Adaptación de la base de datos al nuevo esquema -- Purgamos base de datos antes
--- DELETE FROM stu_picto WHERE id_scene NOT IN (SELECT s.id FROM scene s);
--- --------------------------------------------------------------------------- ALTER TABLE `stu_picto` DROP FOREIGN KEY `stu_picto_scene_fk`;
ALTER TABLE `stu_picto` DROP INDEX `stu_picto_scene_fk`;
-- ----------------------------------------------------------------------------
-- CAMBIOS EN EL SCHEMA DE pictodb
-- ----------------------------------------------------------------------------
SELECT "Actualizando esquema";
-- Rename columns
RENAME TABLE `scene` TO `grid`; RENAME TABLE `scene` TO `grid`;
ALTER TABLE `stu_picto` CHANGE `id_scene` `id_grid` int(11) NOT NULL;
ALTER TABLE `student` CHANGE `id_active_scene` `id_active_grid` int(11) NULL; ALTER TABLE `student` CHANGE `id_active_scene` `id_active_grid` int(11) NULL;
ALTER TABLE `stu_picto` ADD `id_grid` int(11) NULL;
-- Add new column 'id_child_grid'
ALTER TABLE `stu_picto` ADD `id_child_grid` int(11) NULL; ALTER TABLE `stu_picto` ADD `id_child_grid` int(11) NULL;
ALTER TABLE `stu_picto` ADD FOREIGN KEY(`id_child_grid`) REFERENCES `grid`(`id`) ON DELETE SET NULL;
ALTER TABLE `stu_picto` ADD FOREIGN KEY(`id_grid`) REFERENCES `grid`(`id`) ON DELETE CASCADE;
-- Drop column 'categories'
ALTER TABLE `grid` DROP COLUMN `categories`; ALTER TABLE `grid` DROP COLUMN `categories`;
-- Add color to grid column
ALTER TABLE `grid` ADD `color` varchar(7) NULL; ALTER TABLE `grid` ADD `color` varchar(7) NULL;
-- Foreign key stu_picto(id_child_grid) <- grid(id) DROP TABLE IF EXISTS `message`;
ALTER TABLE stu_picto ADD FOREIGN KEY(id_child_grid) REFERENCES grid(id) ON DELETE SET NULL; CREATE TABLE `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
--- --------------------------------------------------------------------------- `id_stu` int(11) NOT NULL,
--- `id_sup` int(11) NOT NULL,
--- Migración de los datos al nuevo esquema `ts` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
--- `content` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
--- --------------------------------------------------------------------------- PRIMARY KEY (`id`),
CONSTRAINT `id_stu_ibfk_1` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`) ON DELETE CASCADE,
DELIMITER $$ CONSTRAINT `id_sup_ibfk_1` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='This table contains all messages on student chat';
DROP PROCEDURE IF EXISTS new_grid_system $$
CREATE PROCEDURE new_grid_system() -- ----------------------------------------------------------------------------
-- ESCENAS CON CATEGORIAS
BEGIN -- ----------------------------------------------------------------------------
DECLARE _id_stu_picto INT; SELECT "Creando tableros para los pictos con categorías...";
DECLARE _id_stu INT;
DECLARE _attributes JSON; -- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
UPDATE stu_picto
DECLARE _free_category_coord_x INT; SET
DECLARE _free_category_coord_y INT; id_child_grid = id
DECLARE _id_cat INT; WHERE
DECLARE _grid_name VARCHAR(100); attributes->>"$.id_cat" = 'null' AND
DECLARE _grid_instances INT; attributes->>"$.coord_y" > 0;
DECLARE _grid_id INT;
DECLARE _id_pic INT; INSERT INTO grid (name, id, id_stu)
DECLARE _id_parent_picto INT; SELECT pe.text, sp.id_child_grid, sp.id_stu
FROM stu_picto sp JOIN picto_exp pe ON
DECLARE LID INT; sp.id_child_grid IS NOT NULL AND
pe.id = (
DECLARE done INT DEFAULT FALSE; SELECT pe2.id FROM picto_exp pe2
DECLARE cursor_stu_picto CURSOR FOR SELECT id, id_stu, attributes FROM pictodb.stu_picto; WHERE
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; pe2.id_pic = sp.id_pic AND
pe2.lang = "es-es"
OPEN cursor_stu_picto; LIMIT 1
read_loop: LOOP );
FETCH cursor_stu_picto INTO _id_stu_picto, _id_stu, _attributes; -- Pictos hijos: los asociamos a su escena correspondiente
-- Control para la finalizacion del bucle SELECT "Asociando pictos bajo categorías a tableros...";
IF done THEN
LEAVE read_loop; UPDATE stu_picto AS A
END IF; JOIN stu_picto AS B on
A.id_scene = B.id_scene AND
-- Carga las variables desde el JSON para free_category_coord e id_cat A.id_stu = B.id_stu AND
IF _attributes->>"$.free_category_coord_x" = 'null' THEN A.attributes->>"$.id_cat" = B.id_pic AND
SET _free_category_coord_x = NULL; B.attributes->>"$.id_cat" = 'null' AND
ELSE B.attributes->>"$.coord_y" > 0
SELECT _attributes->>"$.free_category_coord_x" INTO _free_category_coord_x; SET A.id_grid = B.id_child_grid;
END IF;
-- ----------------------------------------------------------------------------
IF _attributes->>"$.free_category_coord_y" = 'null' THEN -- ESCENAS SIN CATEGORIAS
SET _free_category_coord_y = NULL; -- ----------------------------------------------------------------------------
ELSE
SELECT _attributes->>"$.free_category_coord_y" INTO _free_category_coord_y; SELECT "Asociamos pictos que no están bajo categorías (los de primer nivel o libres) a tableros";
END IF;
UPDATE stu_picto
IF _attributes->>"$.id_cat" = 'null' THEN SET id_grid = id_scene
SET _id_cat = NULL; WHERE id_grid IS NULL;
ELSE
SELECT _attributes->>"$.id_cat" INTO _id_cat; -- Adaptamos JSON
END IF; UPDATE stu_picto
SET
-- Ya no nos hacen falta estos atributos `attributes` = JSON_REPLACE(`attributes`, '$.coord_x', attributes->>'$.free_category_coord_x'),
UPDATE stu_picto `attributes` = JSON_REPLACE(`attributes`, '$.coord_y', attributes->>'$.free_category_coord_y')
SET WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null';
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_x'),
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_y'), -- ----------------------------------------------------------------------------
`attributes` = JSON_REMOVE(`attributes`, '$.id_cat') -- Cambios finales de esquema
WHERE id = _id_stu_picto; -- ----------------------------------------------------------------------------
SELECT "Cambios finales en el esquema y purga del JSON de stu_picto";
-- Pictogramas que estan en escenas sin categorias
IF (_free_category_coord_x IS NOT NULL) OR (_free_category_coord_y IS NOT NULL) THEN ALTER TABLE `stu_picto` DROP COLUMN `id_scene`;
ALTER TABLE `stu_picto` CHANGE `id_grid` `id_grid` int(11) NOT NULL;
-- Pasa las coordenadas libres a coord_x y coord_y, ademas elimina variables antiguas
UPDATE stu_picto UPDATE stu_picto
SET SET
`attributes` = JSON_REPLACE(`attributes`, '$.coord_x', _free_category_coord_x), `attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_x'),
`attributes` = JSON_REPLACE(`attributes`, '$.coord_y', _free_category_coord_y), `attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_y'),
`attributes` = JSON_REMOVE(`attributes`, '$.id_cat');
WHERE id = _id_stu_picto;
-- Pictogramas que estan en escenas con categorias SET FOREIGN_KEY_CHECKS = 1;
ELSE
-- Pictogramas que ya existen en la escena principal y ademas tienen bien las coordenadas, no se tocan
-- Es decir, las free_category_coord y id_cat son NULL
-- Pictogramas que residen en escenas hijas
IF (_id_cat IS NOT NULL) THEN
-- Obtengo el nombre del pictograma asociado (que sera el nombre de la nueva escena)
SELECT `text` FROM picto_exp WHERE id_pic = _id_cat AND lang = 'es-es' INTO _grid_name;
-- Verifico si existe una escena con dicho nombre para el alumno actual
SELECT COUNT(*) FROM grid WHERE name = _grid_name COLLATE utf8_general_ci AND id_stu = _id_stu INTO _grid_instances;
-- Si el nombre de la escena existe mas de una vez, no sabemos a cual corresponde, lo notificamos
IF (_grid_instances > 1) THEN
SELECT concat("El tablero (", _grid_name, ") existe (", _grid_instances, ") veces para el estudiante (", _id_stu, ")");
END IF;
-- La escena ya existe, asocio el pictograma a dicha escena
IF (_grid_instances = 1) THEN
SELECT id FROM grid WHERE name = _grid_name COLLATE utf8_general_ci AND id_stu = _id_stu LIMIT 1 INTO _grid_id;
-- Actualiza el id_grid al que pertenece el picto
UPDATE stu_picto
SET id_grid = _grid_id
WHERE id = _id_stu_picto;
END IF;
-- La escena no existe, la creo, la asocio con el picto padre y asocio el pictograma actual a dicha escena
IF (_grid_instances = 0) THEN
-- Inserto nueva escena
INSERT INTO grid (name,id_stu) VALUES (_grid_name, _id_stu);
SET LID = LAST_INSERT_ID();
-- Esta nueva escena es siempre hija de algun pictograma, lo busco para asociarlo a dicha escena
SELECT id FROM stu_picto WHERE id_pic = _id_cat AND id_stu = _id_stu AND id_child_grid IS NULL LIMIT 1 INTO _id_parent_picto;
-- Actualizo id_child_grid para el pictograma padre
UPDATE stu_picto
SET id_child_grid = LID
WHERE id = _id_parent_picto;
-- Actualizo el id_grid al que pertenece el picto
UPDATE stu_picto
SET id_grid = LID
WHERE id = _id_stu_picto;
END IF;
END IF;
END IF;
END LOOP;
CLOSE cursor_stu_picto;
END $$
DELIMITER ;
CALL new_grid_system();
SET FOREIGN_KEY_CHECKS = 0;
-- Purgamos base de datos antes
DELETE FROM stu_picto WHERE id_scene NOT IN (SELECT s.id FROM scene s);
ALTER TABLE `stu_picto` DROP FOREIGN KEY `stu_picto_scene_fk`;
ALTER TABLE `stu_picto` DROP INDEX `stu_picto_scene_fk`;
-- ----------------------------------------------------------------------------
-- CAMBIOS EN EL SCHEMA DE pictodb
-- ----------------------------------------------------------------------------
SELECT "Actualizando esquema";
RENAME TABLE `scene` TO `grid`;
ALTER TABLE `student` CHANGE `id_active_scene` `id_active_grid` int(11) NULL;
ALTER TABLE `stu_picto` ADD `id_grid` int(11) NULL;
ALTER TABLE `stu_picto` ADD `id_child_grid` int(11) NULL;
ALTER TABLE `stu_picto` ADD FOREIGN KEY(`id_child_grid`) REFERENCES `grid`(`id`) ON DELETE SET NULL;
ALTER TABLE `stu_picto` ADD FOREIGN KEY(`id_grid`) REFERENCES `grid`(`id`) ON DELETE CASCADE;
ALTER TABLE `grid` DROP COLUMN `categories`;
ALTER TABLE `grid` ADD `color` varchar(7) NULL;
-- ----------------------------------------------------------------------------
-- ESCENAS CON CATEGORIAS
-- ----------------------------------------------------------------------------
SELECT "Creando tableros para los pictos con categorías...";
-- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
UPDATE stu_picto
SET
id_child_grid = id
WHERE
attributes->>"$.id_cat" = 'null' AND
attributes->>"$.coord_y" > 0;
INSERT INTO grid (name, id, id_stu)
SELECT pe.text, sp.id_child_grid, sp.id_stu
FROM stu_picto sp JOIN picto_exp pe ON
sp.id_child_grid IS NOT NULL AND
pe.id = (
SELECT pe2.id FROM picto_exp pe2
WHERE
pe2.id_pic = sp.id_pic AND
pe2.lang = "es-es"
LIMIT 1
);
-- Pictos hijos: los asociamos a su escena correspondiente
SELECT "Asociando pictos bajo categorías a tableros...";
UPDATE stu_picto AS A
JOIN stu_picto AS B on
A.id_scene = B.id_scene AND
A.id_stu = B.id_stu AND
A.attributes->>"$.id_cat" = B.id_pic AND
B.attributes->>"$.id_cat" = 'null' AND
B.attributes->>"$.coord_y" > 0
SET A.id_grid = B.id_child_grid;
-- ----------------------------------------------------------------------------
-- ESCENAS SIN CATEGORIAS
-- ----------------------------------------------------------------------------
SELECT "Asociamos pictos que no están bajo categorías (los de primer nivel o libres) a tableros";
UPDATE stu_picto
SET id_grid = id_scene
WHERE id_grid IS NULL;
-- Adaptamos JSON
UPDATE stu_picto
SET
`attributes` = JSON_REPLACE(`attributes`, '$.coord_x', attributes->>'$.free_category_coord_x'),
`attributes` = JSON_REPLACE(`attributes`, '$.coord_y', attributes->>'$.free_category_coord_y')
WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null';
-- ----------------------------------------------------------------------------
-- Cambios finales de esquema
-- ----------------------------------------------------------------------------
SELECT "Cambios finales en el esquema y purga del JSON de stu_picto";
ALTER TABLE `stu_picto` DROP COLUMN `id_scene`;
ALTER TABLE `stu_picto` CHANGE `id_grid` `id_grid` int(11) NOT NULL;
UPDATE stu_picto
SET
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_x'),
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_y'),
`attributes` = JSON_REMOVE(`attributes`, '$.id_cat');
SET FOREIGN_KEY_CHECKS = 1;
SET foreign_key_checks = 0;
ALTER TABLE supervisor ADD role enum('tutor','therapist','office','admin') NOT NULL;
ALTER TABLE supervisor MODIFY name VARCHAR(40) DEFAULT NULL;
ALTER TABLE supervisor MODIFY surname VARCHAR(60) DEFAULT NULL;
ALTER TABLE supervisor MODIFY gender CHAR(1) DEFAULT NULL;
ALTER TABLE supervisor MODIFY postal_code CHAR(10) DEFAULT NULL;
ALTER TABLE supervisor MODIFY lang VARCHAR(5) DEFAULT NULL;
ALTER TABLE student MODIFY name VARCHAR(40) DEFAULT NULL;
ALTER TABLE student MODIFY surname VARCHAR(60) DEFAULT NULL;
ALTER TABLE student MODIFY birthdate DATE DEFAULT NULL;
ALTER TABLE student MODIFY gender CHAR(1) DEFAULT NULL;
ALTER TABLE student MODIFY country CHAR(2) DEFAULT NULL;
ALTER TABLE student MODIFY lang VARCHAR(5) DEFAULT NULL;
ALTER TABLE license ADD `type` enum('trial','official') NOT NULL DEFAULT 'official';
DROP TABLE IF EXISTS `sup_off`;
CREATE TABLE `sup_off` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_sup` int(11) NOT NULL,
`id_off` int(11) DEFAULT NULL,
KEY `fk_sup_off` (`id_sup`),
KEY `fk_off_sup` (`id_off`),
PRIMARY KEY(`id`),
UNIQUE KEY `idx_sup_off` (`id_sup`,`id_off`),
CONSTRAINT `fk_off_sup` FOREIGN KEY (`id_off`) REFERENCES `supervisor` (`id`),
CONSTRAINT `fk_sup_off` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
UPDATE supervisor
SET role = 'office'
WHERE id IN (SELECT admin FROM office WHERE admin IS NOT NULL);
UPDATE supervisor
SET role = 'therapist'
WHERE id NOT IN (SELECT admin FROM office WHERE admin IS NOT NULL);
UPDATE supervisor
SET role = 'tutor'
WHERE id_off IS NULL;
UPDATE license
SET `type` = 'official'
WHERE `type` <> 'trial';
ALTER TABLE supervisor
DROP FOREIGN KEY supervisor_ibfk_1;
ALTER TABLE supervisor
DROP KEY id_off;
ALTER TABLE student
DROP FOREIGN KEY student_ibfk_1;
ALTER TABLE student
DROP KEY id_off;
ALTER TABLE stu_sup
DROP FOREIGN KEY stu_sup_ibfk_1;
ALTER TABLE stu_sup
DROP FOREIGN KEY stu_sup_ibfk_2;
DELIMITER $$
DROP PROCEDURE IF EXISTS supervisor_adapt $$
CREATE PROCEDURE supervisor_adapt()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE id_admin INT;
DECLARE id_off_actual INT;
DECLARE name_sup VARCHAR(80);
DECLARE off_cur CURSOR FOR SELECT id,name,admin FROM pictodb.office;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN off_cur;
read_loop: LOOP
FETCH off_cur INTO id_off_actual,name_sup,id_admin;
-- SELECT concat(id_off_actual, ' ', name_sup, ' ', id_admin);
-- SELECT * from stu_sup where id_sup = 105;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE supervisor SET name = name_sup, surname = '',role = 'office'
WHERE id = id_admin;
-- SELECT * from stu_sup where id_sup = 105;
UPDATE supervisor SET id_off = id_admin WHERE id_off = id_off_actual;
-- SELECT * from stu_sup where id_sup = 105;
UPDATE student SET id_off = id_admin WHERE id_off = id_off_actual;
-- SELECT * from stu_sup where id_sup = 105;
END LOOP;
CLOSE off_cur;
END $$
DELIMITER ;
CALL supervisor_adapt();
INSERT IGNORE INTO stu_sup (id_stu,id_sup)
SELECT id,id_off
FROM student;
INSERT INTO sup_off (id_sup, id_off)
SELECT id, id_off
FROM supervisor;
ALTER TABLE supervisor DROP COLUMN id_off;
ALTER TABLE student DROP COLUMN id_off;
ALTER TABLE stu_sup
ADD CONSTRAINT `stu_sup_ibfk_1` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`);
ALTER TABLE stu_sup
ADD CONSTRAINT `stu_sup_ibfk_2` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`);
DROP TABLE office;
source triggers-enrolments-integrity-constraints.sql;
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_stu` int(11) NOT NULL,
`id_sup` int(11) NOT NULL,
`ts` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`content` varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `id_stu_ibfk_1` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`) ON DELETE CASCADE,
CONSTRAINT `id_sup_ibfk_1` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='This table contains all messages on student chat';
# Acciones a realizar # Acciones a realizar
- En /sails/src/assets lanzar "bower install" - En /sails/src/assets lanzar "bower install"
- En /sails/src lanzar "npm install"
# Changes for new grid system # Changes for new grid system
- Lanzar, desde MySQL el archivo roles/database/files/new-grid-system-adapt.sql - Lanzar desde MySQL el archivo roles/database/files/new-grid-system-adapt2.sql
- Reactivar triggers
...@@ -545,7 +545,8 @@ module.exports = { ...@@ -545,7 +545,8 @@ module.exports = {
* } * }
*/ */
upload: function (req, res) { upload: function (req, res) {
Supervisor.findOne({ id: req.body.owner }).then(function (supervisor) { Supervisor.findOne({ id: req.body.owner })
.then(function (supervisor) {
var pictoFileName; var pictoFileName;
var pictoDirectory = sails.config.pictogram.paths.supervisorCustomPictoDirectory; var pictoDirectory = sails.config.pictogram.paths.supervisorCustomPictoDirectory;
if (!supervisor) if (!supervisor)
...@@ -555,7 +556,7 @@ module.exports = { ...@@ -555,7 +556,7 @@ module.exports = {
sails.log.debug("Uploading picto with FileName: " + pictoFileName); sails.log.debug("Uploading picto with FileName: " + pictoFileName);
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: sails.config.pictogram.maxUploadSize,
dirname: pictoDirectory, dirname: pictoDirectory,
saveAs: pictoFileName saveAs: pictoFileName
}, function whenDone(err, uploadedFiles) { }, function whenDone(err, uploadedFiles) {
...@@ -564,36 +565,37 @@ module.exports = { ...@@ -564,36 +565,37 @@ module.exports = {
if (err || (uploadedFiles.length === 0)) if (err || (uploadedFiles.length === 0))
return res.serverError("Error uploading " + err ? err : ""); return res.serverError("Error uploading " + err ? err : "");
if (req.body.id_pic!=null && req.body.id>=0) { if (req.body.id_pic!=null && req.body.id>=0) {
query = { query = {
id: req.body.id_pic id: req.body.id_pic
} }
Picto.update(query, { Picto.update(query, {
uri:pictoFileName uri:pictoFileName
}) })
.then(updated => { .then(updated => {
return res.ok(updated); return res.ok(updated);
}) })
.catch(err => { .catch(err => {
return res.serverError('Unable to upload picto: ' + err); return res.serverError('Unable to upload picto: ' + err);
}); });
} }
else else {
Picto.create({ Picto.create({
uri: pictoFileName, uri: pictoFileName,
source: 2, // 1 -> SymbolStix, 2 -> custom source: 2, // 1 -> SymbolStix, 2 -> custom
owner: supervisor.id owner: supervisor.id
}) })
.then(picto => { .then(picto => {
return res.ok(picto); return res.ok(picto);
}) })
.catch(err => { .catch(err => {
fs.unlink(uploadedFiles[0].fd); fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err); return res.serverError("Error uploading " + err);
}); });
}); }
}) });
.catch(function (err) { })
return res.serverError("Error uploading picto: " + err); .catch(function (err) {
}); return res.serverError("Error uploading picto: " + err);
});
} }
}; };
...@@ -1343,7 +1343,7 @@ module.exports = { ...@@ -1343,7 +1343,7 @@ module.exports = {
newAvatarFileName = sails.config.pictogram.paths.getStudentAvatarFileName(student.id); newAvatarFileName = sails.config.pictogram.paths.getStudentAvatarFileName(student.id);
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: sails.config.pictogram.maxUploadSize,
dirname: newAvatarDirectory, dirname: newAvatarDirectory,
saveAs: newAvatarFileName saveAs: newAvatarFileName
}, function whenDone(error, uploadedFiles) { }, function whenDone(error, uploadedFiles) {
......
...@@ -757,7 +757,7 @@ module.exports = { ...@@ -757,7 +757,7 @@ module.exports = {
sails.log.debug("Saving file to " + newAvatarDirectory + "/" + newAvatarFileName); sails.log.debug("Saving file to " + newAvatarDirectory + "/" + newAvatarFileName);
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: sails.config.pictogram.maxUploadSize,
dirname: newAvatarDirectory, dirname: newAvatarDirectory,
saveAs: newAvatarFileName saveAs: newAvatarFileName
}, function whenDone(error, uploadedFiles) { }, function whenDone(error, uploadedFiles) {
......
...@@ -19,6 +19,7 @@ module.exports.pictogram = { ...@@ -19,6 +19,7 @@ module.exports.pictogram = {
lang: "es-es" lang: "es-es"
} }
], ],
maxUploadSize: 1048576, // Max upload file size (1MB)
serialSize: 10, // number of characters in generated serial numbers serialSize: 10, // number of characters in generated serial numbers
pageLimit: 10, // number of elements per "page" pageLimit: 10, // number of elements per "page"
trial_license_duration: 3, // number of moths the trial license is valid trial_license_duration: 3, // number of moths the trial license is valid
......
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 sign in to comment