소스 검색

Working on self update feature
Removed column too big (fixes #17)

Sergio Brighenti 6 년 전
부모
커밋
ea6b9a4ebb
6개의 변경된 파일341개의 추가작업 그리고 382개의 파일을 삭제
  1. 29 11
      app/Controllers/UpgradeController.php
  2. 15 0
      app/Exceptions/MaintenanceException.php
  3. 17 0
      app/helpers.php
  4. 1 1
      index.php
  5. 279 366
      package-lock.json
  6. 0 4
      resources/templates/user/index.twig

+ 29 - 11
app/Controllers/UpgradeController.php

@@ -18,11 +18,16 @@ class UpgradeController extends Controller
 	 */
 	 */
 	public function upgrade(Request $request, Response $response): Response
 	public function upgrade(Request $request, Response $response): Response
 	{
 	{
+		if (!is_writable(BASE_DIR)) {
+			$this->session->alert(lang('path_not_writable', BASE_DIR), 'warning');
+			return redirect($response, 'system');
+		}
+
 		try {
 		try {
 			$json = $this->getApiJson();
 			$json = $this->getApiJson();
 		} catch (\RuntimeException $e) {
 		} catch (\RuntimeException $e) {
-			$jsonResponse['message'] = $e->getMessage();
-			return $response->withJson($jsonResponse, 503);
+			$this->session->alert($e->getMessage(), 'danger');
+			return redirect($response, 'system');
 		}
 		}
 
 
 		if (version_compare($json[0]->tag_name, PLATFORM_VERSION, '<=')) {
 		if (version_compare($json[0]->tag_name, PLATFORM_VERSION, '<=')) {
@@ -42,21 +47,34 @@ class UpgradeController extends Controller
 			return redirect($response, 'system');
 			return redirect($response, 'system');
 		}
 		}
 
 
+		$currentFiles = array_merge(
+			glob_recursive(BASE_DIR . 'app/*'),
+			glob_recursive(BASE_DIR . 'bin/*'),
+			glob_recursive(BASE_DIR . 'bootstrap/*'),
+			glob_recursive(BASE_DIR . 'resources/templates/*'),
+			glob_recursive(BASE_DIR . 'resources/lang/*'),
+			glob_recursive(BASE_DIR . 'resources/schemas/*'),
+			glob_recursive(BASE_DIR . 'static/*')
+		);
+
+		removeDirectory(BASE_DIR . 'vendor/');
+
+
 		$updateZip = new ZipArchive();
 		$updateZip = new ZipArchive();
 		$updateZip->open($tmpFile);
 		$updateZip->open($tmpFile);
 
 
-
 		for ($i = 0; $i < $updateZip->numFiles; $i++) {
 		for ($i = 0; $i < $updateZip->numFiles; $i++) {
 			$nameIndex = $updateZip->getNameIndex($i);
 			$nameIndex = $updateZip->getNameIndex($i);
-			if (is_dir(BASE_DIR . $nameIndex)) {
-				continue;
-			}
-			if (file_exists(BASE_DIR . $nameIndex) && md5($updateZip->getFromIndex($i)) !== md5_file(BASE_DIR . $nameIndex)) {
-				$updateZip->extractTo(BASE_DIR, $nameIndex);
-			} elseif (!file_exists(BASE_DIR . $nameIndex)) {
-				$updateZip->extractTo(BASE_DIR, $nameIndex);
+
+			$updateZip->extractTo(BASE_DIR, $nameIndex);
+
+			if (($key = array_search(rtrim(BASE_DIR . $nameIndex, '/'), $currentFiles)) !== false) {
+				unset($currentFiles[$key]);
 			}
 			}
-			print_r($updateZip->getNameIndex($i) . '<br>');
+		}
+
+		foreach ($currentFiles as $extraneous) {
+			unlink($extraneous);
 		}
 		}
 
 
 		$updateZip->close();
 		$updateZip->close();

+ 15 - 0
app/Exceptions/MaintenanceException.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Exceptions;
+
+
+use Exception;
+use Throwable;
+
+class MaintenanceException extends Exception
+{
+	public function __construct(string $message = 'Under Maintenance', int $code = 503, Throwable $previous = null)
+	{
+		parent::__construct($message, $code, $previous);
+	}
+}

+ 17 - 0
app/helpers.php

@@ -259,4 +259,21 @@ if (!function_exists('queryParams')) {
 
 
 		return !empty($params) ? '?' . http_build_query($params) : '';
 		return !empty($params) ? '?' . http_build_query($params) : '';
 	}
 	}
+}
+
+if (!function_exists('glob_recursive')) {
+	/**
+	 * Does not support flag GLOB_BRACE
+	 * @param $pattern
+	 * @param int $flags
+	 * @return array|false
+	 */
+	function glob_recursive($pattern, $flags = 0)
+	{
+		$files = glob($pattern, $flags);
+		foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
+			$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
+		}
+		return $files;
+	}
 }
 }

+ 1 - 1
index.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 require __DIR__ . '/vendor/autoload.php';
 require __DIR__ . '/vendor/autoload.php';
 
 
-define('BASE_DIR', __DIR__ . '/');
+define('BASE_DIR', __DIR__ . DIRECTORY_SEPARATOR);
 define('PLATFORM_VERSION', json_decode(file_get_contents('composer.json'))->version);
 define('PLATFORM_VERSION', json_decode(file_get_contents('composer.json'))->version);
 
 
 require 'bootstrap/app.php';
 require 'bootstrap/app.php';

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 279 - 366
package-lock.json


+ 0 - 4
resources/templates/user/index.twig

@@ -19,7 +19,6 @@
                             <th>Email</th>
                             <th>Email</th>
                             <th>{{ lang('username') }}</th>
                             <th>{{ lang('username') }}</th>
                             <th>{{ lang('user_code') }}</th>
                             <th>{{ lang('user_code') }}</th>
-                            <th>{{ lang('token') }}</th>
                             <th>{{ lang('active') }}</th>
                             <th>{{ lang('active') }}</th>
                             <th>{{ lang('admin') }}</th>
                             <th>{{ lang('admin') }}</th>
                             <th>{{ lang('reg_date') }}</th>
                             <th>{{ lang('reg_date') }}</th>
@@ -35,9 +34,6 @@
                                 <td>
                                 <td>
                                     <pre>{{ user.user_code|default(lang('none')) }}</pre>
                                     <pre>{{ user.user_code|default(lang('none')) }}</pre>
                                 </td>
                                 </td>
-                                <td>
-                                    <pre>{{ user.token|default(lang('none')) }}</pre>
-                                </td>
                                 <td>
                                 <td>
                                     {% if user.active %}
                                     {% if user.active %}
                                         <span class="badge badge-success"><i class="fas fa-check"></i></span>
                                         <span class="badge badge-success"><i class="fas fa-check"></i></span>

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.