像 wordpress 一样更新 Codeigniter 应用程序

Codeigniter application update like wordpress

我用 Codeigniter 创建了一个项目。我想添加一个可以像 Wordpress 一样更新我的项目的系统。示例:假设我 运行 Project V.1.0 但是当我想实现 V2.0 时,我的客户可能会通过上传 zip 更新我的项目文件。 我希望这个系统像 Wordpress 一样。而且我不知道该用什么git。因为我有一些客户。我希望他们下载或收集包含更新版本文件的 zip 文件。他们通过 Codeigniter 项目将这个 zip 上传到服务器,项目将自动更新到 v2.0

上传 zip,解压并替换所有文件。 保持与项目相同的 zip 结构。

像这样:

update.zip

./root/application/controllers/*.*
./root/application/views/*.*
...

这只有在用户 运行 apache/nginx 对文件系统有足够的权限时才有可能。

因为你的问题比较宽泛,我给你一个比较宽泛的回答;通常我什至不会回答这些类型的问题,但我恰好有一个我前段时间制作的相关脚本。

这不是即插即用的,并且有一些来自 CakePHP 的第三方依赖项需要自动加载。

该脚本创建数组中所有指定文件夹的图像,添加文件清单和标识符文件,例如版本 2. 然后可以将图像(zip 文件)上传到站点 运行 版本 1,只要它具有相同的更新模型。上传后,只要 zip 文件中有有效的标识符文件,模型就会提取文件(以防止用户上传不相关的 zip 文件并破坏系统);该脚本还会创建站点的当前图像(版本 1),以防需要恢复。

该脚本还具有恢复以前版本的功能,该功能将删除版本 2 而不是版本 1 中的所有附加文件,并恢复版本 1 的原始文件。

我对此不提供任何支持。但希望你觉得它有点帮助 - 它有点被黑在一起,但在我有限的测试中它工作正常。

控制器:

<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * 
 * NEOU CMS v4 CI Edition
 * @copyright (c) 2018, Alexander Fagard
 * @requires PHP version >= 5.6
 * 
 * You cannot redistribute this document without written permission from the author
 * 
 */
class Update extends MY_Backend {

    static $perm = ['admin_only' => true];

    public function __construct() {
        parent::__construct();
        $this->lang->load('core_update');
        $this->load->model('backend/core_update_model', 'update');
    }

    public function index() {
        $this->tpl->head($this->lang->line('update_heading'));
        $this->tpl->body();
        $this->output->append_output($this->messages->display());
        $data = array(
            'is_local' => $this->localization->is_local(),
            'previous_exist' => $this->update->previous_exists()
        );
        $this->parser->parse('backend/core_update', $data);
        $this->tpl->footer();
    }

    public function restore() {
        try {
            $this->update->restore_previous();
            rmdir_recursive($this->update->updates_folder);
            $this->messages->success($this->lang->line('update_previous_restored'));
        } catch (Exception $e) {
            $this->messages->error($e->getMessage());
        } finally {
            redirect(CMS_DIR_NAME . '/update');
        }
    }

    public function apply() {
        $this->load->helper('byte_helper');
        try {
            $this->update->mk_update_dir();
            $config['upload_path'] = $this->update->updates_folder;
            $config['overwrite'] = true;
            $config['allowed_types'] = 'zip';
            $config['max_size'] = convert_bytes_to_type(file_upload_max_size(), 'KB');
            $config['file_ext_tolower'] = true;
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('update')) {
                throw new Exception($this->upload->display_errors('', ''));
            }
            $data = $this->upload->data();
            $this->update->apply_update($data['full_path']);
            $this->messages->success($this->lang->line('update_applied'));
        } catch (Exception $e) {
            $this->messages->error($e->getMessage());
        } finally {
            redirect(CMS_DIR_NAME . '/update');
        }
    }

    public function create() {
        if (!$this->localization->is_local()) {
            show_error($this->lang->line('update_localhost'), 500);
        }
        try {
            $this->update->create_update();
            $this->messages->success(sprintf($this->lang->line('update_created'), $this->update->files_processed));
        } catch (Exception $e) {
            $this->messages->error($e->getMessage());
        } finally {
            redirect(CMS_DIR_NAME . '/update');
        }
    }

}

型号:https://pastebin.com/UuzQ1tds