feat: Add integrations dropdown and toggle functionality for trustmate.io orders
- Introduced a new dropdown button for integrations in the order details page. - Implemented functionality to resend orders to apilo.com and toggle trustmate.io status. - Enhanced the order details template with new dropdown menu and JavaScript for handling dropdown behavior. - Added new textarea for producer data in the producer edit page with CKEditor integration. - Updated product edit page to include GPSR information with textarea and CKEditor. - Improved update process with detailed logging and error handling during version updates. - Updated version number to 0.233.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2245,3 +2245,14 @@ textarea.form-control {
|
|||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#integrationsDropdownBtn {
|
||||||
|
width: 50px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu-right {
|
||||||
|
a {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
admin/temp/2/s_cache_21a4da48e5fa14e992150d116fb212cc
Normal file
1
admin/temp/2/s_cache_21a4da48e5fa14e992150d116fb212cc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
YToyOntpOjA7aToxNzY4OTA0MTA3O2k6MTtzOjg6Ik1hcmlhbmVrIjt9
|
||||||
@@ -218,16 +218,48 @@ if ( $this -> next_order_id )
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
$grid -> buttons[] = [
|
$grid -> buttons[] = [
|
||||||
'label' => 'Wyślij ponownie zamówienie do apilo.com',
|
'label' => '',
|
||||||
'url' => '/admin/shop_order/send_order_to_apilo/order_id=' . $this -> order['id'],
|
'url' => '#',
|
||||||
'icon' => 'fa-refresh',
|
'icon' => 'fa-ellipsis-v',
|
||||||
'class' => 'btn btn-primary btn-sm mr5 ml5 pull-right btn-send-order-to-apilo'
|
'class' => 'btn btn-primary',
|
||||||
|
'id' => 'integrationsDropdownBtn'
|
||||||
];
|
];
|
||||||
$grid -> default_buttons = false;
|
$grid -> default_buttons = false;
|
||||||
$grid -> external_code = $out;
|
$grid -> external_code = $out;
|
||||||
echo $grid -> draw();
|
echo $grid -> draw();
|
||||||
?>
|
?>
|
||||||
|
<div class="dropdown-menu dropdown-menu-right" id="integrationsDropdownMenu">
|
||||||
|
<a class="dropdown-item btn-send-order-to-apilo" href="/admin/shop_order/send_order_to_apilo/order_id=<?= $this -> order['id'];?>">
|
||||||
|
<i class="fa fa-refresh"></i> Wyślij ponownie zamówienie do apilo.com
|
||||||
|
</a>
|
||||||
|
<a class="dropdown-item btn-toggle-trustmate" href="#">
|
||||||
|
<i class="fa fa-<?= $this -> order['trustmate_send'] ? 'times' : 'check';?>"></i>
|
||||||
|
<?= $this -> order['trustmate_send'] ? 'Odznacz zamówienie jako wysłane do trustmate.io' : 'Zaznacz zamówienie jako wysłane do trustmate.io';?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
$( function() {
|
||||||
|
var btn = $( '#integrationsDropdownBtn' );
|
||||||
|
var menu = $( '#integrationsDropdownMenu' );
|
||||||
|
|
||||||
|
// Opakuj przycisk w dropdown wrapper
|
||||||
|
btn.wrap( '<div class="dropdown d-inline-block pull-right"></div>' );
|
||||||
|
menu.appendTo( btn.parent() );
|
||||||
|
|
||||||
|
// Ręczna obsługa toggle dropdown
|
||||||
|
btn.on( 'click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
menu.toggleClass( 'show' );
|
||||||
|
});
|
||||||
|
|
||||||
|
// Zamknij dropdown po kliknięciu poza nim
|
||||||
|
$( document ).on( 'click', function(e) {
|
||||||
|
if ( !btn.is( e.target ) && !menu.is( e.target ) && menu.has( e.target ).length === 0 ) {
|
||||||
|
menu.removeClass( 'show' );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
$( function()
|
$( function()
|
||||||
{
|
{
|
||||||
var timer = '';
|
var timer = '';
|
||||||
@@ -603,4 +635,54 @@ function order_status_change($order_id, $status, $email) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$( 'body' ).on( 'click', '.btn-toggle-trustmate', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var currentState = <?= $this -> order['trustmate_send'] ? 'true' : 'false';?>;
|
||||||
|
|
||||||
|
$.alert({
|
||||||
|
title: 'Potwierdź',
|
||||||
|
content: currentState ? 'Czy na pewno chcesz odznaczyć zamówienie jako wysłane do trustmate.io?' : 'Czy na pewno chcesz zaznaczyć zamówienie jako wysłane do trustmate.io?',
|
||||||
|
type: 'orange',
|
||||||
|
closeIcon: true,
|
||||||
|
closeIconClass: 'fa fa-times',
|
||||||
|
typeAnimated: true,
|
||||||
|
animation: 'opacity',
|
||||||
|
columnClass: 'col-12 col-lg-10',
|
||||||
|
theme: 'modern',
|
||||||
|
icon: 'fa fa-question',
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Tak',
|
||||||
|
btnClass: 'btn-success',
|
||||||
|
keys: ['enter'],
|
||||||
|
action: function() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
cache: false,
|
||||||
|
url: '/admin/shop_order/toggle_trustmate_send/',
|
||||||
|
data: {
|
||||||
|
order_id: <?= $this -> order['id'];?>
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$( '#overlay' ).show();
|
||||||
|
},
|
||||||
|
success: function( response ) {
|
||||||
|
$( '#overlay' ).hide();
|
||||||
|
var data = jQuery.parseJSON( response );
|
||||||
|
if ( data.result === true ) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
text: 'Nie',
|
||||||
|
btnClass: 'btn-dark',
|
||||||
|
action: function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -70,8 +70,20 @@ ob_start();
|
|||||||
'value' => $this -> producer['languages'][$lg[ 'id']]['description'],
|
'value' => $this -> producer['languages'][$lg[ 'id']]['description'],
|
||||||
'inline' => true
|
'inline' => true
|
||||||
] );?>
|
] );?>
|
||||||
|
<?= \Html::textarea( [
|
||||||
|
'label' => 'Dane producenta',
|
||||||
|
'name' => 'data[' . $lg['id'] . ']',
|
||||||
|
'id' => 'data_' . $lg['id'],
|
||||||
|
'value' => $this -> producer['languages'][$lg[ 'id']]['data'],
|
||||||
|
'inline' => true
|
||||||
|
] );?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
|
$( '#data_<?= $lg[ 'id' ];?>').ckeditor({
|
||||||
|
toolbar: 'MyToolbar',
|
||||||
|
height: '250'
|
||||||
|
});
|
||||||
|
|
||||||
$( '#description_<?= $lg[ 'id' ];?>').ckeditor({
|
$( '#description_<?= $lg[ 'id' ];?>').ckeditor({
|
||||||
toolbar: 'MyToolbar',
|
toolbar: 'MyToolbar',
|
||||||
height: '250'
|
height: '250'
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ ob_start();
|
|||||||
<li><i class="fa fa-exchange"></i>Produkty powiązane</li>
|
<li><i class="fa fa-exchange"></i>Produkty powiązane</li>
|
||||||
<li><i class="fa fa-file-excel-o"></i>XML</li>
|
<li><i class="fa fa-file-excel-o"></i>XML</li>
|
||||||
<li><i class="fa fa-file-o"></i>Dodatkowe pola</li>
|
<li><i class="fa fa-file-o"></i>Dodatkowe pola</li>
|
||||||
|
<li><i class="fa fa-file-o"></i>GPSR</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="resp-tabs-container settings-tabs">
|
<div class="resp-tabs-container settings-tabs">
|
||||||
<div>
|
<div>
|
||||||
@@ -407,25 +408,13 @@ ob_start();
|
|||||||
'value' => $this->product['additional_message_text']
|
'value' => $this->product['additional_message_text']
|
||||||
]);
|
]);
|
||||||
?>
|
?>
|
||||||
<?
|
|
||||||
$producers[''] = '--- wybierz producenta ---';
|
|
||||||
foreach ($this->producers as $producer)
|
|
||||||
$producers[$producer['id']] = $producer['name'];
|
|
||||||
?>
|
|
||||||
<?= \Html::select([
|
|
||||||
'label' => 'Producent',
|
|
||||||
'name' => 'producer_id',
|
|
||||||
'id' => 'producer_id',
|
|
||||||
'values' => $producers,
|
|
||||||
'value' => $this->product['producer_id']
|
|
||||||
]); ?>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div id="languages-seo">
|
<div id="languages-seo">
|
||||||
<ul class="resp-tabs-list languages-seo htabs">
|
<ul class="resp-tabs-list languages-seo htabs">
|
||||||
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
||||||
<? if ($lg['status']) : ?>
|
<? if ($lg['status']) : ?>
|
||||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></a></li>
|
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||||
<? endif; ?>
|
<? endif; ?>
|
||||||
<?
|
<?
|
||||||
endforeach;
|
endforeach;
|
||||||
@@ -702,6 +691,52 @@ ob_start();
|
|||||||
<? endforeach; endif;?>
|
<? endforeach; endif;?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<?
|
||||||
|
$producers[''] = '--- wybierz producenta ---';
|
||||||
|
foreach ($this->producers as $producer)
|
||||||
|
$producers[$producer['id']] = $producer['name'];
|
||||||
|
?>
|
||||||
|
<?= \Html::select([
|
||||||
|
'label' => 'Producent',
|
||||||
|
'name' => 'producer_id',
|
||||||
|
'id' => 'producer_id',
|
||||||
|
'values' => $producers,
|
||||||
|
'value' => $this->product['producer_id']
|
||||||
|
]); ?>
|
||||||
|
<div id="gpsr-seo">
|
||||||
|
<ul class="resp-tabs-list gpsr-seo htabs">
|
||||||
|
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
|
||||||
|
<? if ($lg['status']) : ?>
|
||||||
|
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||||
|
<? endif; ?>
|
||||||
|
<? endforeach; endif; ?>
|
||||||
|
</ul>
|
||||||
|
<div class="resp-tabs-container gpsr-seo">
|
||||||
|
<? if ( is_array ($this -> languages ) ): foreach ( $this -> languages as $lg ):?>
|
||||||
|
<? if ( $lg['status'] ):?>
|
||||||
|
<div>
|
||||||
|
<?= \Html::textarea( [
|
||||||
|
'label' => 'Informacje o bezpieczeństwie ('.$lg['name'].')',
|
||||||
|
'name' => 'security_information[' . $lg['id'] . ']',
|
||||||
|
'id' => 'security_information_' . $lg['id'],
|
||||||
|
'value' => $this->product['languages'][$lg['id']]['security_information']
|
||||||
|
] );?>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function () {
|
||||||
|
$( '#security_information_<?= $lg[ 'id' ];?>').ckeditor({
|
||||||
|
toolbar: 'MyToolbar',
|
||||||
|
height: '250'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<? endif; ?>
|
||||||
|
<? endforeach; endif;?>
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?
|
<?
|
||||||
@@ -951,6 +986,12 @@ echo $grid->draw();
|
|||||||
tabidentify: 'languages-seo'
|
tabidentify: 'languages-seo'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#gpsr-seo').easyResponsiveTabs({
|
||||||
|
width: 'auto',
|
||||||
|
fit: true,
|
||||||
|
tabidentify: 'gpsr-seo'
|
||||||
|
});
|
||||||
|
|
||||||
$('#languages-tabs').easyResponsiveTabs({
|
$('#languages-tabs').easyResponsiveTabs({
|
||||||
width: 'auto',
|
width: 'auto',
|
||||||
fit: true,
|
fit: true,
|
||||||
|
|||||||
@@ -115,4 +115,19 @@ class ShopOrder
|
|||||||
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
|
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toggle_trustmate_send
|
||||||
|
public static function toggle_trustmate_send()
|
||||||
|
{
|
||||||
|
global $mdb;
|
||||||
|
|
||||||
|
$order_id = (int)\S::get( 'order_id' );
|
||||||
|
$order = $mdb -> get( 'pp_shop_orders', [ 'trustmate_send' ], [ 'id' => $order_id ] );
|
||||||
|
|
||||||
|
$new_value = $order['trustmate_send'] ? 0 : 1;
|
||||||
|
$mdb -> update( 'pp_shop_orders', [ 'trustmate_send' => $new_value ], [ 'id' => $order_id ] );
|
||||||
|
|
||||||
|
echo json_encode( [ 'result' => true, 'trustmate_send' => $new_value ] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,101 +7,343 @@ class Update
|
|||||||
{
|
{
|
||||||
global $mdb, $settings;
|
global $mdb, $settings;
|
||||||
|
|
||||||
|
@file_put_contents( '../libraries/update_log.txt', '' );
|
||||||
|
|
||||||
|
$log = [];
|
||||||
|
$log[] = '[START] Rozpoczęcie aktualizacji - ' . date('Y-m-d H:i:s');
|
||||||
|
$log[] = '[INFO] Aktualna wersja: ' . \S::get_version();
|
||||||
|
|
||||||
\S::delete_session( 'new-version' );
|
\S::delete_session( 'new-version' );
|
||||||
|
|
||||||
$versions = file_get_contents( 'https://shoppro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
$versions_url = 'https://shoppro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'];
|
||||||
|
$versions = @file_get_contents( $versions_url );
|
||||||
|
|
||||||
|
if ( $versions === false )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się pobrać listy wersji z: ' . $versions_url;
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = '[OK] Pobrano listę wersji';
|
||||||
$versions = explode( PHP_EOL, $versions );
|
$versions = explode( PHP_EOL, $versions );
|
||||||
|
$log[] = '[INFO] Znaleziono ' . count($versions) . ' wersji do sprawdzenia';
|
||||||
|
|
||||||
foreach ( $versions as $ver )
|
foreach ( $versions as $ver )
|
||||||
{
|
{
|
||||||
$ver = trim( $ver );
|
$ver = trim( $ver );
|
||||||
if ( floatval( $ver ) > (float)\S::get_version() )
|
if ( floatval( $ver ) > (float)\S::get_version() )
|
||||||
{
|
{
|
||||||
|
$log[] = '[INFO] Aktualizacja do wersji: ' . $ver;
|
||||||
|
|
||||||
if ( strlen( $ver ) == 5 )
|
if ( strlen( $ver ) == 5 )
|
||||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||||
else
|
else
|
||||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||||
|
|
||||||
$file = file_get_contents( 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '.zip' );
|
$zip_url = 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '.zip';
|
||||||
|
$log[] = '[INFO] Pobieranie pliku ZIP: ' . $zip_url;
|
||||||
|
|
||||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
$file = @file_get_contents( $zip_url );
|
||||||
if ( !fwrite( $dlHandler, $file ) )
|
|
||||||
return false;
|
if ( $file === false )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się pobrać pliku ZIP';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_size = strlen( $file );
|
||||||
|
$log[] = '[OK] Pobrano plik ZIP, rozmiar: ' . $file_size . ' bajtów';
|
||||||
|
|
||||||
|
if ( $file_size < 100 )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Plik ZIP jest za mały (prawdopodobnie błąd pobierania)';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$dlHandler = @fopen( 'update.zip' , 'w' );
|
||||||
|
if ( !$dlHandler )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się otworzyć pliku update.zip do zapisu';
|
||||||
|
$log[] = '[INFO] Katalog roboczy: ' . getcwd();
|
||||||
|
$log[] = '[INFO] Uprawnienia katalogu: ' . substr(sprintf('%o', fileperms('.')), -4);
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$written = fwrite( $dlHandler, $file );
|
||||||
fclose( $dlHandler );
|
fclose( $dlHandler );
|
||||||
|
|
||||||
if ( !file_exists( 'update.zip' ) )
|
if ( $written === false || $written === 0 )
|
||||||
return false;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się zapisać pliku ZIP (zapisano: ' . ($written === false ? 'false' : $written) . ' bajtów)';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = '[OK] Zapisano plik ZIP (' . $written . ' bajtów)';
|
||||||
|
|
||||||
|
if ( !file_exists( 'update.zip' ) )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Plik update.zip nie istnieje po zapisie';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$actual_size = filesize( 'update.zip' );
|
||||||
|
$log[] = '[OK] Plik update.zip istnieje, rozmiar na dysku: ' . $actual_size . ' bajtów';
|
||||||
|
|
||||||
/* aktualizacja bazy danych */
|
/* aktualizacja bazy danych */
|
||||||
$url = 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt';
|
$sql_url = 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt';
|
||||||
$ch = curl_init( $url );
|
$log[] = '[INFO] Sprawdzanie aktualizacji SQL: ' . $sql_url;
|
||||||
|
|
||||||
|
$ch = curl_init( $sql_url );
|
||||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt( $ch, CURLOPT_HEADER, false );
|
curl_setopt( $ch, CURLOPT_HEADER, false );
|
||||||
$response = curl_exec( $ch );
|
$response = curl_exec( $ch );
|
||||||
|
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||||
|
curl_close( $ch );
|
||||||
|
|
||||||
if ( $response and strpos( $content_type, 'text/plain' ) !== false )
|
$sql = [];
|
||||||
$sql = explode( PHP_EOL, $response );
|
if ( $response && strpos( $content_type, 'text/plain' ) !== false )
|
||||||
|
|
||||||
if ( is_array( $sql ) and !empty( $sql ) ) foreach ( $sql as $query )
|
|
||||||
{
|
{
|
||||||
if ( $sql )
|
$sql = explode( PHP_EOL, $response );
|
||||||
|
$log[] = '[OK] Pobrano ' . count($sql) . ' zapytań SQL';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$log[] = '[INFO] Brak aktualizacji SQL (HTTP: ' . $http_code . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_array( $sql ) && !empty( $sql ) )
|
||||||
|
{
|
||||||
|
$sql_success = 0;
|
||||||
|
$sql_errors = 0;
|
||||||
|
foreach ( $sql as $query )
|
||||||
|
{
|
||||||
|
$query = trim( $query );
|
||||||
|
if ( !empty( $query ) )
|
||||||
{
|
{
|
||||||
$result = $mdb->query( $query );
|
$result = $mdb->query( $query );
|
||||||
|
if ( $result ) $sql_success++;
|
||||||
|
else $sql_errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$log[] = '[INFO] Wykonano zapytania SQL - sukces: ' . $sql_success . ', błędy: ' . $sql_errors;
|
||||||
|
}
|
||||||
|
|
||||||
/* usuwanie zbędnych plików */
|
/* usuwanie zbędnych plików */
|
||||||
$url = 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt';
|
$files_url = 'https://shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt';
|
||||||
$ch = curl_init( $url );
|
$log[] = '[INFO] Sprawdzanie plików do usunięcia: ' . $files_url;
|
||||||
|
|
||||||
|
$ch = curl_init( $files_url );
|
||||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt( $ch, CURLOPT_HEADER, false );
|
curl_setopt( $ch, CURLOPT_HEADER, false );
|
||||||
$response = curl_exec( $ch );
|
$response = curl_exec( $ch );
|
||||||
|
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
|
||||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||||
|
curl_close( $ch );
|
||||||
|
|
||||||
if ( $response and strpos( $content_type, 'text/plain' ) !== false )
|
$files = [];
|
||||||
|
if ( $response && strpos( $content_type, 'text/plain' ) !== false )
|
||||||
$files = explode( PHP_EOL, $response );
|
$files = explode( PHP_EOL, $response );
|
||||||
|
|
||||||
if ( is_array( $files ) and !empty( $files ) ) foreach ( $files as $file )
|
$deleted_files = 0;
|
||||||
|
$deleted_dirs = 0;
|
||||||
|
if ( is_array( $files ) && !empty( $files ) )
|
||||||
|
{
|
||||||
|
foreach ( $files as $file )
|
||||||
{
|
{
|
||||||
if ( strpos( $file, 'F: ' ) !== false )
|
if ( strpos( $file, 'F: ' ) !== false )
|
||||||
{
|
{
|
||||||
$file = substr( $file, 3, strlen( $file ) );
|
$file = substr( $file, 3, strlen( $file ) );
|
||||||
if ( file_exists( $file ) )
|
if ( file_exists( $file ) )
|
||||||
unlink( $file );
|
{
|
||||||
|
if ( @unlink( $file ) ) $deleted_files++;
|
||||||
|
else $log[] = '[WARNING] Nie udało się usunąć pliku: ' . $file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strpos( $file, 'D: ' ) !== false )
|
if ( strpos( $file, 'D: ' ) !== false )
|
||||||
{
|
{
|
||||||
$dir = substr( $file, 3, strlen( $file ) );
|
$dir_to_delete = substr( $file, 3, strlen( $file ) );
|
||||||
if ( is_dir( $dir ) )
|
if ( is_dir( $dir_to_delete ) )
|
||||||
\S::delete_dir( $dir );
|
{
|
||||||
|
\S::delete_dir( $dir_to_delete );
|
||||||
|
$deleted_dirs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$log[] = '[INFO] Usunięto plików: ' . $deleted_files . ', katalogów: ' . $deleted_dirs;
|
||||||
|
|
||||||
/* wgrywanie nowych plików */
|
/* wgrywanie nowych plików */
|
||||||
$file_name = 'update.zip';
|
$file_name = 'update.zip';
|
||||||
|
$log[] = '[INFO] Rozpoczęcie rozpakowywania pliku ZIP';
|
||||||
|
|
||||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||||
|
$log[] = '[INFO] Ścieżka pathinfo: ' . $path;
|
||||||
|
|
||||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||||
$zip = new \ZipArchive;
|
$log[] = '[INFO] Ścieżka docelowa (po obcięciu): ' . $path;
|
||||||
$res = $zip -> open( $file_name );
|
|
||||||
if ( $res === TRUE )
|
if ( !is_dir( $path ) )
|
||||||
{
|
{
|
||||||
$zip -> extractTo( $path );
|
$log[] = '[ERROR] Ścieżka docelowa nie istnieje: ' . $path;
|
||||||
$zip -> close();
|
self::saveUpdateLog( $log );
|
||||||
unlink( $file_name );
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !is_writable( $path ) )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Brak uprawnień do zapisu w: ' . $path;
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = '[OK] Ścieżka docelowa istnieje i jest zapisywalna';
|
||||||
|
|
||||||
|
$zip = new \ZipArchive;
|
||||||
|
$res = $zip->open( $file_name );
|
||||||
|
|
||||||
|
if ( $res !== true )
|
||||||
|
{
|
||||||
|
$zip_errors = [
|
||||||
|
\ZipArchive::ER_EXISTS => 'Plik już istnieje',
|
||||||
|
\ZipArchive::ER_INCONS => 'Archiwum ZIP jest niespójne',
|
||||||
|
\ZipArchive::ER_INVAL => 'Nieprawidłowy argument',
|
||||||
|
\ZipArchive::ER_MEMORY => 'Błąd alokacji pamięci',
|
||||||
|
\ZipArchive::ER_NOENT => 'Plik nie istnieje',
|
||||||
|
\ZipArchive::ER_NOZIP => 'Plik nie jest archiwum ZIP',
|
||||||
|
\ZipArchive::ER_OPEN => 'Nie można otworzyć pliku',
|
||||||
|
\ZipArchive::ER_READ => 'Błąd odczytu',
|
||||||
|
\ZipArchive::ER_SEEK => 'Błąd seek',
|
||||||
|
];
|
||||||
|
$error_msg = isset( $zip_errors[$res] ) ? $zip_errors[$res] : 'Nieznany błąd (' . $res . ')';
|
||||||
|
$log[] = '[ERROR] Nie udało się otworzyć pliku ZIP: ' . $error_msg;
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = '[OK] Otwarto archiwum ZIP, liczba plików: ' . $zip->numFiles;
|
||||||
|
|
||||||
|
$extracted_count = 0;
|
||||||
|
$extract_errors = 0;
|
||||||
|
$skipped_dirs = 0;
|
||||||
|
|
||||||
|
for ( $i = 0; $i < $zip->numFiles; $i++ )
|
||||||
|
{
|
||||||
|
$filename = $zip->getNameIndex( $i );
|
||||||
|
$filename_clean = str_replace( '\\', '/', $filename );
|
||||||
|
|
||||||
|
if ( substr( $filename_clean, -1 ) === '/' )
|
||||||
|
{
|
||||||
|
$dir_path = $path . '/' . $filename_clean;
|
||||||
|
if ( !is_dir( $dir_path ) )
|
||||||
|
{
|
||||||
|
if ( @mkdir( $dir_path, 0755, true ) )
|
||||||
|
$log[] = '[DIR] Utworzono katalog: ' . $filename_clean;
|
||||||
|
else
|
||||||
|
$log[] = '[WARNING] Nie udało się utworzyć katalogu: ' . $filename_clean;
|
||||||
|
}
|
||||||
|
$skipped_dirs++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$target_file = $path . '/' . $filename_clean;
|
||||||
|
$target_dir = dirname( $target_file );
|
||||||
|
|
||||||
|
if ( !is_dir( $target_dir ) )
|
||||||
|
{
|
||||||
|
if ( !@mkdir( $target_dir, 0755, true ) )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się utworzyć katalogu dla: ' . $filename_clean;
|
||||||
|
$extract_errors++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_existed = file_exists( $target_file );
|
||||||
|
$old_size = $file_existed ? filesize( $target_file ) : 0;
|
||||||
|
$old_mtime = $file_existed ? filemtime( $target_file ) : 0;
|
||||||
|
|
||||||
|
$content = $zip->getFromIndex( $i );
|
||||||
|
if ( $content === false )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się odczytać z ZIP: ' . $filename_clean;
|
||||||
|
$extract_errors++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$write_result = @file_put_contents( $target_file, $content );
|
||||||
|
|
||||||
|
if ( $write_result === false )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się zapisać: ' . $filename_clean . ' (uprawnienia?)';
|
||||||
|
$extract_errors++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$new_size = filesize( $target_file );
|
||||||
|
$new_mtime = filemtime( $target_file );
|
||||||
|
|
||||||
|
if ( $file_existed )
|
||||||
|
{
|
||||||
|
if ( $old_mtime !== $new_mtime || $old_size !== $new_size )
|
||||||
|
$log[] = '[UPDATED] ' . $filename_clean . ' (' . $old_size . ' -> ' . $new_size . ' bajtów)';
|
||||||
|
else
|
||||||
|
$log[] = '[UNCHANGED] ' . $filename_clean . ' (nie zmieniono - identyczny?)';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$log[] = '[NEW] ' . $filename_clean . ' (' . $new_size . ' bajtów)';
|
||||||
|
}
|
||||||
|
$extracted_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = '[OK] Rozpakowano ' . $extracted_count . ' plików, błędów: ' . $extract_errors . ', katalogów: ' . $skipped_dirs;
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
if ( @unlink( $file_name ) )
|
||||||
|
$log[] = '[OK] Usunięto plik update.zip';
|
||||||
|
else
|
||||||
|
$log[] = '[WARNING] Nie udało się usunąć pliku update.zip';
|
||||||
|
|
||||||
|
/* aktualizacja wersji */
|
||||||
|
$version_file = '../libraries/version.ini';
|
||||||
|
$updateThis = @fopen( $version_file, 'w' );
|
||||||
|
|
||||||
|
if ( !$updateThis )
|
||||||
|
{
|
||||||
|
$log[] = '[ERROR] Nie udało się otworzyć pliku version.ini do zapisu';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => false, 'log' => $log ];
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
|
||||||
fwrite( $updateThis, $ver );
|
fwrite( $updateThis, $ver );
|
||||||
fclose( $updateThis );
|
fclose( $updateThis );
|
||||||
|
|
||||||
return true;
|
$log[] = '[OK] Zaktualizowano plik version.ini do wersji: ' . $ver;
|
||||||
|
$log[] = '[SUCCESS] Aktualizacja do wersji ' . $ver . ' zakończona pomyślnie';
|
||||||
|
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => true, 'log' => $log ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$log[] = '[INFO] Brak nowych wersji do zainstalowania';
|
||||||
|
self::saveUpdateLog( $log );
|
||||||
|
return [ 'success' => true, 'log' => $log, 'no_updates' => true ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function saveUpdateLog( $log )
|
||||||
|
{
|
||||||
|
$log_content = implode( "\n", $log );
|
||||||
|
@file_put_contents( '../libraries/update_log.txt', $log_content );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update0197()
|
public static function update0197()
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.096
|
0.233
|
||||||
Reference in New Issue
Block a user