forked from verdnatura/hedera-web
Refactor, unused code removed
This commit is contained in:
parent
e8f73c5147
commit
bf5ad50f94
|
@ -1,4 +1,4 @@
|
|||
hedera-web (1.408.14) stable; urgency=low
|
||||
hedera-web (1.408.15) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ Hedera.Conf = new Class({
|
|||
|
||||
if (verificationToken) {
|
||||
params.verificationToken = verificationToken;
|
||||
this.conn.send('core/restore-password', params,
|
||||
this.conn.send('user/restore-password', params,
|
||||
this._onPassChange.bind(this));
|
||||
} else {
|
||||
let userId = this.gui.user.id;
|
||||
|
|
|
@ -1,42 +1,36 @@
|
|||
|
||||
Hedera.Contact = new Class
|
||||
({
|
||||
Hedera.Contact = new Class({
|
||||
Extends: Hedera.Form
|
||||
|
||||
,activate: function ()
|
||||
{
|
||||
,activate: function() {
|
||||
var self = this;
|
||||
this.$.contactForm.onsubmit = function ()
|
||||
{ self._onSubmit (); return false; };
|
||||
this.$.contactForm.onsubmit = function() {
|
||||
self._onSubmit(); return false;
|
||||
};
|
||||
|
||||
this.refreshCaptcha();
|
||||
}
|
||||
|
||||
,refreshCaptcha: function ()
|
||||
{
|
||||
,refreshCaptcha: function() {
|
||||
params = {
|
||||
'srv': 'rest:core/captcha',
|
||||
'stamp': new Date ().getTime ()
|
||||
srv: 'rest:misc/captcha',
|
||||
stamp: new Date().getTime()
|
||||
};
|
||||
this.$.captchaImg.src = '?'+ Vn.Url.makeUri(params);
|
||||
}
|
||||
|
||||
,_onSubmit: function ()
|
||||
{
|
||||
,_onSubmit: function() {
|
||||
this.conn.sendForm(this.$.contactForm,
|
||||
this._onResponse.bind(this));
|
||||
}
|
||||
|
||||
,_onResponse: function (json, error)
|
||||
{
|
||||
,_onResponse: function(json) {
|
||||
var form = this.$.contactForm;
|
||||
|
||||
if (json)
|
||||
{
|
||||
if (json) {
|
||||
form.reset();
|
||||
Htk.Toast.showMessage(_('DataSentSuccess'));
|
||||
}
|
||||
else
|
||||
} else
|
||||
Htk.Toast.showError(_('ErrorSendingData'));
|
||||
|
||||
form['captcha'].value = '';
|
||||
|
|
|
@ -98,7 +98,7 @@ module.exports = new Class({
|
|||
if (!user)
|
||||
Htk.Toast.showError(_('Please write your user name'));
|
||||
else
|
||||
this._conn.send('core/recover-password', {recoverUser: user},
|
||||
this._conn.send('user/recover-password', {recoverUser: user},
|
||||
this._onPasswordRecovered.bind(this));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hedera-web",
|
||||
"version": "1.408.14",
|
||||
"version": "1.408.15",
|
||||
"description": "Verdnatura web page",
|
||||
"license": "GPL-3.0",
|
||||
"repository": {
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
|
||||
Hedera.DeliveryNote = new Class({
|
||||
Extends: Hedera.Report,
|
||||
|
||||
onTicketReady: function(form) {
|
||||
if (form.$.method != 'PICKUP')
|
||||
Vn.Node.setText(this.$.method, _('Agency'));
|
||||
else
|
||||
Vn.Node.setText(this.$.method, _('Warehouse'));
|
||||
},
|
||||
|
||||
discountRenderer: function(column, form) {
|
||||
column.value = form.$.discount ? form.$.discount : null;
|
||||
},
|
||||
|
||||
subtotalRenderer: function(column, form) {
|
||||
column.value = this.subtotal(form);
|
||||
},
|
||||
|
||||
subtotal: function(form) {
|
||||
var price = form.$.price;
|
||||
var discount = form.$.discount;
|
||||
return form.$.quantity * price *((100 - discount) / 100);
|
||||
},
|
||||
|
||||
serviceSubtotal: function(column, form) {
|
||||
column.value = form.$.quantity * form.$.price;
|
||||
},
|
||||
|
||||
onServicesChanged: function(model) {
|
||||
this.$.services.node.style.display =
|
||||
model.numRows > 0 ? 'block' : 'none';
|
||||
},
|
||||
|
||||
onPackagesChanged: function(model) {
|
||||
this.$.packages.node.style.display =
|
||||
model.numRows > 0 ? 'block' : 'none';
|
||||
}
|
||||
});
|
|
@ -1,45 +0,0 @@
|
|||
*
|
||||
{
|
||||
font-size: 4mm;
|
||||
}
|
||||
.sheet
|
||||
{
|
||||
height: auto;
|
||||
}
|
||||
h2
|
||||
{
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
.header
|
||||
{
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
.header > div > p
|
||||
{
|
||||
margin: .1em 0;
|
||||
}
|
||||
.important
|
||||
{
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
.address,
|
||||
.total
|
||||
{
|
||||
margin-top: .8em;
|
||||
}
|
||||
.total
|
||||
{
|
||||
text-align: right;
|
||||
}
|
||||
.htk-grid
|
||||
{
|
||||
margin-top: 1em;
|
||||
}
|
||||
.packages
|
||||
{
|
||||
width: 50%;
|
||||
margin-left: 0;
|
||||
display: none;
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
<vn>
|
||||
<vn-group>
|
||||
<db-form id="ticket" on-ready="onTicketReady">
|
||||
<db-model property="model" id="ticket-data" conn="conn" lot="lot">
|
||||
CALL myTicket_get(#ticket)
|
||||
</db-model>
|
||||
</db-form>
|
||||
</vn-group>
|
||||
<div id="report" class="sheet">
|
||||
<h2>
|
||||
#<htk-text column="id" form="ticket"/>
|
||||
</h2>
|
||||
<div class="header">
|
||||
<div>
|
||||
<p>
|
||||
<t>Preparation</t> <htk-text form="ticket" column="shipped" format="%D"/>
|
||||
</p>
|
||||
<p>
|
||||
<t>Delivery</t> <htk-text form="ticket" column="landed" format="%D"/>
|
||||
</p>
|
||||
<p>
|
||||
<span id="method"></span> <htk-text form="ticket" column="agency"/>
|
||||
</p>
|
||||
</div>
|
||||
<div class="address">
|
||||
<p>
|
||||
<htk-text form="ticket" column="nickname"/>
|
||||
</p>
|
||||
<p>
|
||||
<htk-text form="ticket" column="street"/>
|
||||
</p>
|
||||
<p>
|
||||
<htk-text form="ticket" column="postalCode"/>
|
||||
<htk-text form="ticket" column="city"/>
|
||||
(<htk-text form="ticket" column="province"/>)
|
||||
</p>
|
||||
</div>
|
||||
<div class="total">
|
||||
<p class="important">
|
||||
<t>Total</t>
|
||||
<htk-text format="%.2d€" form="ticket" column="taxBase"/>
|
||||
</p>
|
||||
<p class="important">
|
||||
<t>Total + tax</t>
|
||||
<htk-text format="%.2d€" form="ticket" column="total"/>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<htk-grid>
|
||||
<db-model property="model" id="movements" conn="conn" lot="lot">
|
||||
CALL myTicket_getRows(#ticket)
|
||||
</db-model>
|
||||
<htk-column-spin title="_Ref" column="itemFk"/>
|
||||
<htk-column-spin title="_Amount" column="quantity"/>
|
||||
<htk-column-text title="_Item" column="concept"/>
|
||||
<htk-column-text title="_S1" column="size"/>
|
||||
<htk-column-text title="_Cat" column="category"/>
|
||||
<htk-column-spin title="_Price" column="price" unit="€" digits="2"/>
|
||||
<htk-column-spin title="_Disc" column="discount" unit="%" renderer="discountRenderer"/>
|
||||
<htk-column-spin title="_Subtotal" unit="€" digits="2" renderer="subtotalRenderer"/>
|
||||
</htk-grid>
|
||||
<htk-grid id="services">
|
||||
<db-model
|
||||
property="model"
|
||||
id="services"
|
||||
conn="conn"
|
||||
lot="lot"
|
||||
on-status-changed="onServicesChanged">
|
||||
CALL myTicket_getServices(#ticket)
|
||||
</db-model>
|
||||
<htk-column-text title="_Service" column="description"/>
|
||||
<htk-column-spin title="_Amount" column="quantity"/>
|
||||
<htk-column-spin title="_Price" column="price" unit="€" digits="2"/>
|
||||
<htk-column-spin title="_Subtotal" unit="€" digits="2" renderer="serviceSubtotal"/>
|
||||
</htk-grid>
|
||||
<htk-grid id="packages" class="packages">
|
||||
<db-model
|
||||
property="model"
|
||||
conn="conn"
|
||||
lot="lot"
|
||||
on-status-changed="onPackagesChanged">
|
||||
CALL myTicket_getPackages(#ticket)
|
||||
</db-model>
|
||||
<htk-column-spin title="_Ref" column="id"/>
|
||||
<htk-column-spin title="_Amount" column="quantity"/>
|
||||
<htk-column-text title="_Packaging" column="name"/>
|
||||
</htk-grid>
|
||||
</div>
|
||||
</vn>
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
Hedera.ItemsReport = new Class({
|
||||
Extends: Hedera.Report
|
||||
});
|
|
@ -1,45 +0,0 @@
|
|||
*
|
||||
{
|
||||
font-size: 4mm;
|
||||
}
|
||||
.sheet
|
||||
{
|
||||
height: auto;
|
||||
}
|
||||
h1
|
||||
{
|
||||
font-weight: normal;
|
||||
font-size: 200%;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
margin-bottom: 8mm;
|
||||
}
|
||||
.htk-grid
|
||||
{
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
padding: 0;
|
||||
}
|
||||
thead > tr
|
||||
{
|
||||
border-bottom: 1px solid #333;
|
||||
height: 10mm;
|
||||
}
|
||||
th
|
||||
{
|
||||
font-weight: normal;
|
||||
}
|
||||
td
|
||||
{
|
||||
padding-left: 2mm;
|
||||
}
|
||||
tbody > tr
|
||||
{
|
||||
height: 18mm;
|
||||
}
|
||||
.cell-image img
|
||||
{
|
||||
width: 15mm;
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<vn>
|
||||
<div id="report" class="items sheet">
|
||||
<h1>
|
||||
<t>Item list</t>
|
||||
</h1>
|
||||
<htk-grid>
|
||||
<db-model
|
||||
property="model"
|
||||
lot="lot"
|
||||
conn="conn">
|
||||
<custom>
|
||||
CALL item_getList(#warehouse, CURDATE(), #realm, #rate)
|
||||
</custom>
|
||||
</db-model>
|
||||
<htk-column-image
|
||||
column="image"
|
||||
directory="catalog"
|
||||
subdir="200x200"/>
|
||||
<htk-column-spin
|
||||
title="_Id"
|
||||
column="id"/>
|
||||
<htk-column-text
|
||||
title="_Item"
|
||||
column="name"/>
|
||||
<htk-column-text
|
||||
title="_Cat"
|
||||
column="category"/>
|
||||
<htk-column-text
|
||||
title="_Siz"
|
||||
column="size"/>
|
||||
<htk-column-text
|
||||
title="_Ste"
|
||||
column="stems"/>
|
||||
<htk-column-spin
|
||||
title="_Pack"
|
||||
column="grouping"/>
|
||||
<htk-column-spin
|
||||
title="_Aval"
|
||||
column="available"/>
|
||||
<htk-column-text
|
||||
title="_Col"
|
||||
column="inkFk"/>
|
||||
<htk-column-text
|
||||
title="_Ori"
|
||||
column="origin"/>
|
||||
<htk-column-text
|
||||
title="_Price"
|
||||
column="price"
|
||||
format="%.2d€"
|
||||
class="price"/>
|
||||
</htk-grid>
|
||||
</div>
|
||||
</vn>
|
|
@ -18,12 +18,12 @@ class Supplant extends Vn\Web\JsonRequest {
|
|||
if (!$isClient)
|
||||
throw new Web\ForbiddenException(s('The user is not a client'));
|
||||
|
||||
$isWorker = $db->getValue(
|
||||
'SELECT COUNT(*) > 0 FROM vn.worker WHERE id = #',
|
||||
$hasAccount = $db->getValue(
|
||||
'SELECT COUNT(*) > 0 FROM account.account WHERE id = #',
|
||||
[$userId]
|
||||
);
|
||||
if ($isWorker)
|
||||
throw new Web\ForbiddenException(s('Workers cannot be supplanted'));
|
||||
if ($hasAccount)
|
||||
throw new Web\ForbiddenException(s('The user is not impersonable'));
|
||||
|
||||
return $this->service->createToken($_REQUEST['supplantUser']);
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
include __DIR__.'/account.php';
|
||||
|
||||
/**
|
||||
* Sets the user password.
|
||||
*/
|
||||
class SetPassword extends Vn\Web\JsonRequest {
|
||||
const PARAMS = [
|
||||
'setUser'
|
||||
,'setPassword'
|
||||
];
|
||||
|
||||
function run($db) {
|
||||
$setUser = $_REQUEST['setUser'];
|
||||
$setPassword = $_REQUEST['setPassword'];
|
||||
|
||||
$userId = $db->getValue(
|
||||
'SELECT id FROM account.user WHERE `name` = #',
|
||||
[$setUser]
|
||||
);
|
||||
$db->query('CALL account.user_setPassword(#, #)',
|
||||
[$userId, $setPassword]);
|
||||
Account::sync($db, $setUser, $setPassword);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE bucket
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12)
|
||||
SET
|
||||
bucket_id = @col2,
|
||||
bucket_type_id = @col4,
|
||||
description = @col5,
|
||||
x_size = @col6,
|
||||
y_size = @col7,
|
||||
z_size = @col8,
|
||||
entry_date = STR_TO_DATE(@col10, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col11, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col12, '%Y%m%d%H%i')
|
|
@ -1,10 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE bucket_type
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6)
|
||||
SET
|
||||
bucket_type_id = @col2,
|
||||
description = @col3,
|
||||
entry_date = STR_TO_DATE(@col4, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col5, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col6, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE `feature`
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7)
|
||||
SET
|
||||
item_id = @col2,
|
||||
feature_type_id = @col3,
|
||||
feature_value = @col4,
|
||||
entry_date = STR_TO_DATE(@col5, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col6, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col7, '%Y%m%d%H%i')
|
|
@ -1,10 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE genus
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6)
|
||||
SET
|
||||
genus_id = @col2,
|
||||
latin_genus_name = @col3,
|
||||
entry_date = STR_TO_DATE(@col4, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col5, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col6, '%Y%m%d%H%i')
|
|
@ -1,13 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE item
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12)
|
||||
SET
|
||||
id = @col2,
|
||||
product_name = @col4,
|
||||
name = @col5,
|
||||
plant_id = @col7,
|
||||
group_id = @col9,
|
||||
entry_date = STR_TO_DATE(@col10, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col11, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col12, '%Y%m%d%H%i')
|
|
@ -1,12 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE `item_feature`
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8)
|
||||
SET
|
||||
item_id = @col2,
|
||||
feature = @col3,
|
||||
regulation_type = @col4,
|
||||
presentation_order = @col5,
|
||||
entry_date = STR_TO_DATE(@col6, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col7, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col8, '%Y%m%d%H%i')
|
|
@ -1,10 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE item_group
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6)
|
||||
SET
|
||||
group_code = @col2,
|
||||
dutch_group_description = @col3,
|
||||
entry_date = STR_TO_DATE(@col4, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col5, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col6, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE plant
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9)
|
||||
SET
|
||||
plant_id = @col3,
|
||||
genus_id = @col4,
|
||||
specie_id = @col5,
|
||||
entry_date = STR_TO_DATE(@col7, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col8, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col9, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE specie
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7)
|
||||
SET
|
||||
specie_id = @col2,
|
||||
genus_id = @col3,
|
||||
latin_species_name = @col4,
|
||||
entry_date = STR_TO_DATE(@col5, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col6, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col7, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE supplier
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12, @col13, @col14, @col15, @col16, @col17, @col18, @col19, @col20)
|
||||
SET
|
||||
GLNAddressCode = @col2,
|
||||
supplier_id = @col4,
|
||||
company_name = @col3,
|
||||
entry_date = STR_TO_DATE(@col9, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col10, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col11, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE `type`
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7)
|
||||
SET
|
||||
type_id = @col2,
|
||||
type_group_id = @col3,
|
||||
description = @col4,
|
||||
entry_date = STR_TO_DATE(@col5, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col6, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col7, '%Y%m%d%H%i')
|
|
@ -1,11 +0,0 @@
|
|||
LOAD DATA LOCAL INFILE #file
|
||||
INTO TABLE `value`
|
||||
FIELDS TERMINATED BY ';'
|
||||
LINES TERMINATED BY '\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7)
|
||||
SET
|
||||
type_id = @col2,
|
||||
type_value = @col3,
|
||||
type_description = @col4,
|
||||
entry_date = STR_TO_DATE(@col5, '%Y%m%d'),
|
||||
expiry_date = IFNULL(NULL,STR_TO_DATE(@col6, '%Y%m%d')),
|
||||
change_date_time = STR_TO_DATE(@col7, '%Y%m%d%H%i')
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Update extends Vn\Lib\Method {
|
||||
function run($db) {
|
||||
$db->selectDb('edi');
|
||||
$db->getHandler()->options(MYSQLI_OPT_LOCAL_INFILE, TRUE);
|
||||
|
||||
$tmpDir = '/tmp/floricode';
|
||||
|
||||
// Establish the FTP connection
|
||||
|
||||
$ftpConf = $db->getRow('SELECT host, user, password FROM ftpConfig');
|
||||
|
||||
echo "Openning FTP connection to {$ftpConf['host']}\n";
|
||||
$ftpConn = ftp_connect($ftpConf['host']);
|
||||
|
||||
if (!$ftpConn)
|
||||
throw new Exception('Can not connect to '. $ftpConf['host']);
|
||||
|
||||
if (!ftp_login($ftpConn, $ftpConf['user'], $ftpConf['password']))
|
||||
throw new Exception('Can not login to '. $ftpConf['user'] .'@'. $ftpConf['host']);
|
||||
ftp_pasv($ftpConn, true);
|
||||
|
||||
// Gets the list with the tables to update
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$res = $db->query(
|
||||
'SELECT fileName, toTable, file, updated FROM fileConfig');
|
||||
|
||||
$dwFiles = [];
|
||||
|
||||
if (!file_exists($tmpDir))
|
||||
mkdir($tmpDir);
|
||||
|
||||
while ($row = $res->fetch_assoc())
|
||||
try {
|
||||
$file = $row['file'];
|
||||
$table = $row['toTable'];
|
||||
$baseName = $row['fileName'];
|
||||
|
||||
if ($row['updated']) {
|
||||
$updated = DateTime::createFromFormat('Y-m-d', $row['updated']);
|
||||
$updated->setTime(0, 0, 0);
|
||||
} else
|
||||
$updated = NULL;
|
||||
|
||||
$remoteFile = "codes/$file.ZIP";
|
||||
$zipFile = "$tmpDir/$file.zip";
|
||||
$ucDir = "$tmpDir/$file";
|
||||
|
||||
// Downloads and decompress the file with the data
|
||||
|
||||
if (!isset($dwFiles[$file])) {
|
||||
$dwFiles[$file] = TRUE;
|
||||
|
||||
echo "Downloading $remoteFile\n";
|
||||
if (!ftp_get($ftpConn, $zipFile, $remoteFile, FTP_BINARY))
|
||||
throw new Exception("Error downloading $remoteFile to $zipFile");
|
||||
|
||||
$zip = new ZipArchive;
|
||||
|
||||
if ($zip->open($zipFile) !== TRUE)
|
||||
throw new Exception("Can not open $zipFile");
|
||||
|
||||
@mkdir($ucDir, 0774, TRUE);
|
||||
|
||||
if (!$zip->extractTo($ucDir))
|
||||
throw new Exception("Can not uncompress file $zipFile");
|
||||
|
||||
$zip->close();
|
||||
unlink($zipFile);
|
||||
}
|
||||
|
||||
foreach (glob("$ucDir/$baseName*.txt") as $fileName)
|
||||
break;
|
||||
|
||||
if (empty($fileName))
|
||||
throw new Exception("Import file for table $table does not exist");
|
||||
|
||||
// If data is updated, omits the table
|
||||
|
||||
$lastUpdated = substr($fileName, -10, 6);
|
||||
$lastUpdated = DateTime::createFromFormat('dmy', $lastUpdated);
|
||||
$lastUpdated->setTime(0, 0, 0);
|
||||
|
||||
if (isset($updated) && $lastUpdated <= $updated) {
|
||||
echo "Table $table is updated, omitted\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Updates the table
|
||||
|
||||
echo "Dumping data to table $table\n";
|
||||
|
||||
$db->query("START TRANSACTION");
|
||||
$db->query("DELETE FROM {$db->quote($table)}");
|
||||
$db->queryFromFile(__DIR__."/sql/$table", ['file' => $fileName]);
|
||||
$db->query("UPDATE fileConfig SET updated = # WHERE fileName = #",
|
||||
[$lastUpdated, $baseName]
|
||||
);
|
||||
$db->query("COMMIT");
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
$db->query('ROLLBACK');
|
||||
}
|
||||
|
||||
shell_exec("rm -R $tmpDir");
|
||||
ftp_close($ftpConn);
|
||||
|
||||
echo "Update completed\n";
|
||||
}
|
||||
}
|
|
@ -22,6 +22,12 @@ class Image {
|
|||
case IMAGETYPE_GIF:
|
||||
$image = imagecreatefromgif($srcFile);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$image = imagecreatefromwebp($srcFile);
|
||||
break;
|
||||
case IMAGETYPE_BMP:
|
||||
$image = imagecreatefrombmp($srcFile);
|
||||
break;
|
||||
default:
|
||||
throw new UserException(s('Bad file format'));
|
||||
} else
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Vn\Lib;
|
||||
use Vn\Lib\UserException;
|
||||
|
||||
/**
|
||||
* Uploads a access module.
|
||||
*/
|
||||
class AccessVersion extends Vn\Web\JsonRequest {
|
||||
const PARAMS = [
|
||||
'appName'
|
||||
,'newVersion'
|
||||
];
|
||||
|
||||
function run($db) {
|
||||
// Checks for file errors.
|
||||
|
||||
$moduleFile = $_FILES['moduleFile'];
|
||||
|
||||
if (empty($moduleFile['name']))
|
||||
throw new UserException(s('File not choosed'));
|
||||
|
||||
if ($moduleFile['error'] != 0) {
|
||||
switch ($_FILES['image']['error']) {
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
$message = 'ErrIniSize';
|
||||
break;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$message = 'ErrFormSize';
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$message = 'ErrPartial';
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$message = 'ErrNoFile';
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$message = 'ErrNoTmpDir';
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$message = 'ErrCantWrite';
|
||||
break;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$message = 'ErrExtension';
|
||||
break;
|
||||
default:
|
||||
$message = 'ErrDefault';
|
||||
break;
|
||||
}
|
||||
|
||||
throw new Lib\Exception(s($message));
|
||||
}
|
||||
|
||||
// Defining parameters
|
||||
|
||||
$appName = $_REQUEST['appName'];
|
||||
$newVersion = $_REQUEST['newVersion'];
|
||||
|
||||
$accessDir = _DATA_DIR .'/'. $this->app->getName() .'/vn-access';
|
||||
$headFile = "$accessDir/$appName.7z";
|
||||
$archiveRelPath = ".archive/$appName/$newVersion.7z";
|
||||
$archiveFullPath = "$accessDir/$archiveRelPath";
|
||||
|
||||
// Updates the application
|
||||
|
||||
rename($moduleFile['tmp_name'], $archiveFullPath);
|
||||
chmod($archiveFullPath, 0644);
|
||||
|
||||
@unlink($headFile);
|
||||
symlink($archiveRelPath, $headFile);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue