Skip to content

Commit

Permalink
changed source repo uzulla/fc2blog to fc2blog/blog
Browse files Browse the repository at this point in the history
- If you want continue to follow the uzulla's development version. Check `app/config.sample.php` and `fc2blog_installer.php`'s header.
  • Loading branch information
uzulla committed Mar 16, 2021
1 parent b8a038d commit a8cc49c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 28 deletions.
3 changes: 3 additions & 0 deletions app/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
// publicとappの位置関係を修正した場合には変更してください
// Please edit the path when change `app` and `public` relative path condition.
define('WWW_DIR', __DIR__ . '/../public/'); // this path need finish with slash.

// 別のGitHub repoを追従する場合に設定してください
// define('GITHUB_REPO', '/uzulla/fc2blog');
28 changes: 19 additions & 9 deletions app/src/Model/SystemUpdateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@

class SystemUpdateModel
{
/** @var string */
static public $releases_url = "https://www.github.com/uzulla/fc2blog/releases"; // TODO: change to fc2blog/blog
/** @var string */
static public $releases_api_url = "https://api.github.com/repos/uzulla/fc2blog/releases"; // TODO: change to fc2blog/blog
/** @var string */
static public $cached_release_info_path = __DIR__ . "/../../temp/github_release_cache.json";
/** @var string */
static public $version_file_path = __DIR__ . "/../../version";

public static function getReleasesUrl(): string
{
return defined("GITHUB_REPO")
? "https://www.github.com" . GITHUB_REPO . "/releases"
: "https://www.github.com/fc2blog/blog/releases";
}

public static function getReleasesApiUrl(): string
{
return defined("GITHUB_REPO")
? "https://api.github.com/repos" . GITHUB_REPO . "/releases"
: "https://api.github.com/repos/fc2blog/blog/releases";
}

/**
* Get download url of `fc2blog_dist.zip` in assets from release array.
* @param array $release
Expand Down Expand Up @@ -71,7 +81,7 @@ public static function getReleaseInfo(): ?array
// JSONのrelease情報JSONをGitHub APIより取得
$options = ['http' => ['header' => "User-Agent: fc2blog_installer"]];
$releases_json = @file_get_contents(
static::$releases_api_url,
static::getReleasesApiUrl(),
false,
stream_context_create($options)
);
Expand Down Expand Up @@ -238,7 +248,7 @@ public static function updateSystemByLocalZip(string $dist_zip_path)
if ($tmp_dir_app . "/temp" === $files_in_tmp_dir_app_row) continue;
if ($tmp_dir_app . "/config.php" === $files_in_tmp_dir_app_row) continue;
// delete/reset dir/files.
static::rm_r($app_dir . substr($files_in_tmp_dir_app_row, strlen($tmp_dir_app)+1));
static::rm_r($app_dir . substr($files_in_tmp_dir_app_row, strlen($tmp_dir_app) + 1));
static::copy_r($files_in_tmp_dir_app_row, $app_dir); // todo error handling
}

Expand All @@ -248,14 +258,14 @@ public static function updateSystemByLocalZip(string $dist_zip_path)
if ($tmp_dir_app . "/user_uploads" === $files_in_tmp_dir_public_row) continue;
if ($tmp_dir_app . "/uploads" === $files_in_tmp_dir_public_row) continue;
// delete/reset dir/files.
static::rm_r($public_dir . substr($files_in_tmp_dir_public_row, strlen($tmp_dir_public)+1));
static::rm_r($public_dir . substr($files_in_tmp_dir_public_row, strlen($tmp_dir_public) + 1));
static::copy_r($files_in_tmp_dir_public_row, WWW_DIR); // todo error handling
}

// index.phpのみ、環境によって動的なので更新する
$index_php = file_get_contents(WWW_DIR."/index.php");
$index_php = file_get_contents(WWW_DIR . "/index.php");
$index_php = preg_replace('/\n\$app_dir_path.+;/u', "\n\$app_dir_path = '" . APP_DIR . "';", $index_php);
file_put_contents(WWW_DIR."/index.php", $index_php);
file_put_contents(WWW_DIR . "/index.php", $index_php);

} finally {
static::rmdir_r($tmp_path);
Expand Down
12 changes: 6 additions & 6 deletions app/src/Web/Controller/Admin/SystemUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function index(Request $request): string
$request->generateNewSig();
$release_list = SystemUpdateModel::getReleaseInfo();
$this->set('release_list', $release_list);
$this->set('repo_site_url', SystemUpdateModel::$releases_url);
$this->set('repo_site_url', SystemUpdateModel::getReleasesUrl());
$this->set('now_version', SystemUpdateModel::getVersion(true));
return 'admin/system_update/index.twig';
}
Expand All @@ -27,16 +27,16 @@ public function update(Request $request): string
// TODO unit test

// check sig
if(!$request->isValidSig()){
if (!$request->isValidSig()) {
$this->setWarnMessage(__("Request failed: invalid sig, please retry."));
$this->redirect($request, Html::url($request, ['controller'=>'system_update', 'action'=>'index']));
$this->redirect($request, Html::url($request, ['controller' => 'system_update', 'action' => 'index']));
}

// check request
$request_version = $request->get('version');
if(is_null($request_version)){
if (is_null($request_version)) {
$this->setWarnMessage(__("Request failed: notfound request version."));
$this->redirect($request, Html::url($request, ['controller'=>'system_update', 'action'=>'index']));
$this->redirect($request, Html::url($request, ['controller' => 'system_update', 'action' => 'index']));
}

$release_list = SystemUpdateModel::getReleaseInfo();
Expand All @@ -51,7 +51,7 @@ public function update(Request $request): string
$this->setInfoMessage(__("Update success."));

// redirect to index
$this->redirect($request, Html::url($request, ['controller'=>'system_update', 'action'=>'index']));
$this->redirect($request, Html::url($request, ['controller' => 'system_update', 'action' => 'index']));

throw new LogicException("must be redirect");
}
Expand Down
7 changes: 5 additions & 2 deletions dist_zip/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.PHONY:
build:
make clean
echo `git branch --contains |cut -d " " -f 2`
git clone --depth=1 --branch=`git branch --contains |cut -d " " -f 2` https://github.com/uzulla/fc2blog.git fc2blog
# git clone from GITHUB_REPO_URL env
if [ ! -z "${GITHUB_REPO_URL}" ]; then git clone --depth=1 --branch=`git branch --contains |cut -d " " -f 2` ${GITHUB_REPO_URL} fc2blog ;fi
# or not
if [ -z "${GITHUB_REPO_URL}" ]; then git clone --depth=1 --branch=`git branch --contains |cut -d " " -f 2` https://github.com/fc2blog/blog.git fc2blog ;fi
rm -rf fc2blog/.git
cd fc2blog && php ../../composer.phar install --no-dev --optimize-autoloader -q
# get tag from current commit id.
Expand Down Expand Up @@ -30,6 +32,7 @@ build-no-pushed-branch:
mkdir fc2blog
cp -a ../app ../public ../composer.json ../composer.lock fc2blog
-rm fc2blog/app/temp/installed.lock
-rm fc2blog/app/temp/github_release_cache.json
cd fc2blog && php ../../composer.phar install --no-dev --optimize-autoloader
rm fc2blog/composer.*
echo "dev:"`git branch --contains |cut -d " " -f 2 | grep -e '.'`":"`git rev-parse --short HEAD` > fc2blog/app/version
Expand Down
34 changes: 24 additions & 10 deletions dist_zip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ Create a ZIP file for distribute.

The branch name to build will be same as `git branch --contains |cut -d " " -f 2` (So, same as your local checkout branch).

## IMPORTANT NOTICE
## build zip

The script will be make a zip that cloned from `https://github.com/uzulla/fc2blog` (not `fc2blog/blog`).
```
$ make build
$ ls fc2blog_dist.zip
fc2blog_dist.zip
```

> This setup is temporary. will be change to `fc2blog/blog` in future.
`fc2blog_dist.zip` is distributable zip.

## build zip
that contain `app`, `public`, and `app/vendor/`(libraries that installed by the composer).

### build zip from your repo

```
$ export GITHUB_REPO_URL="https://github.com/uzulla/fc2blog.git"
$ make build
$ ls fc2blog_dist_*
fc2blog_dist_*****.zip
```

`fc2blog_dist_*****.zip` is distributable zip. (***** is short commit id)
### build local src (no checkout)

that contain `app`, `public`, and `app/vendor/`(libraries that installed by the composer).
```
$ make build-no-pushed-branch
```

## test on Ubuntu vm(docker)

Expand All @@ -41,6 +48,12 @@ root@2792c09097ef:/# exit

> All data is not permanent. All data will be lost when bash exited.
### test local src (no checkout)

```
$ make test-no-pushed-branch
```

## clean

```
Expand All @@ -51,7 +64,7 @@ $ make clean

[`installer/fc2blog_installer.php`](installer/fc2blog_installer.php)

Handy deploy tool.
Handy deploy tool.

Installation can be done by simply, uploading one small php file and running it.

Expand All @@ -70,7 +83,8 @@ Installation can be done by simply, uploading one small php file and running it.

### how to use

1. Upload [`installer/fc2blog_installer.php`](installer/fc2blog_installer.php) to server's (VirtualHost's) document root.
1. Upload [`installer/fc2blog_installer.php`](installer/fc2blog_installer.php) to server's (VirtualHost's) document
root.
2. Open `fc2blog_installer.php` by browser.
3. Fill some configuration and click execute button
4. Ta-da! After that, follow the normal installer.
2 changes: 1 addition & 1 deletion dist_zip/installer/fc2blog_installer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<?php
// config
define("GITHUB_REPO", "/uzulla/fc2blog"); // TODO: change to fc2blog/blog
define("GITHUB_REPO", "/fc2blog/blog");
define("GITHUB_REPO_URL", "https://github.com" . GITHUB_REPO . "/");
define("GITHUB_REPO_RELEASE_API_URL", "https://api.github.com/repos" . GITHUB_REPO . "/releases");

Expand Down

0 comments on commit a8cc49c

Please sign in to comment.