Переглянути джерело

Improve update API

Update script must implement 4 functions:
- apply_update() to perform the update (most important). Return true if
  all is ok, else false.
- need_info_update() returns true if we need more info for update, else
  false. If this function always returns false, you don't need to
  implement following functions (but it's better to not forget)
- ask_info_update() should be a HTML form to ask infos. Method must be
  post and action must point to _url('update', 'apply') (or leave it
  blank)
- save_info_update() is called for POST requests (to save form from
  ask_info_update())
Marien Fressinaud 11 роки тому
батько
коміт
9a5d6245fb

+ 22 - 15
app/Controllers/updateController.php

@@ -84,26 +84,33 @@ class FreshRSS_update_Controller extends Minz_ActionController {
 
 	public function applyAction() {
 		require(UPDATE_FILENAME);
-		$res = apply_update();
 
-		if ($res === true) {
-			@unlink(UPDATE_FILENAME);
+		if (Minz_Request::isPost()) {
+			save_info_update();
+		}
 
-			// TODO: record last update
+		if (!need_info_update()) {
+			$res = apply_update();
 
-			Minz_Session::_param('notification', array(
-				'type' => 'good',
-				'content' => Minz_Translate::t('update_finished')
-			));
+			if ($res === true) {
+				@unlink(UPDATE_FILENAME);
 
-			Minz_Request::forward(array(), true);
-		} else {
-			Minz_Session::_param('notification', array(
-				'type' => 'bad',
-				'content' => Minz_Translate::t('update_problem', $res)
-			));
+				// TODO: record last update
+
+				Minz_Session::_param('notification', array(
+					'type' => 'good',
+					'content' => Minz_Translate::t('update_finished')
+				));
 
-			Minz_Request::forward(array('c' => 'update'), true);
+				Minz_Request::forward(array(), true);
+			} else {
+				Minz_Session::_param('notification', array(
+					'type' => 'bad',
+					'content' => Minz_Translate::t('update_problem', $res)
+				));
+
+				Minz_Request::forward(array('c' => 'update'), true);
+			}
 		}
 	}
 }

+ 9 - 0
app/views/update/apply.phtml

@@ -0,0 +1,9 @@
+<?php $this->partial('aside_configure'); ?>
+
+<div class="post">
+	<a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('back_to_rss_feeds'); ?></a>
+
+	<h1><?php echo _t('update_system'); ?></h1>
+
+	<?php ask_info_update(); ?>
+</div>

+ 2 - 0
app/views/update/index.phtml

@@ -1,6 +1,8 @@
 <?php $this->partial('aside_configure'); ?>
 
 <div class="post">
+	<a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('back_to_rss_feeds'); ?></a>
+
 	<h1><?php echo _t('update_system'); ?></h1>
 
 	<?php if (!empty($this->message)) { ?>