* Refactor zanodeModel::editSnapshot.
This commit is contained in:
@@ -120,10 +120,10 @@ $config->zanode->snapshotDtable->fieldList['actions']['title'] = $lang->actions;
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['type'] = 'actions';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['menu'] = array('editSnapshot', 'restoreSnapshot', 'deleteSnapshot');
|
||||
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['icon'] = 'edit';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['hint'] = $lang->zanode->editSnapshot;
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['className'] = 'editSnapshot';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['url'] = array('module' => 'zanode', 'method' => 'editSnapshot', 'params' => 'snapshotID={id}');
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['icon'] = 'edit';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['hint'] = $lang->zanode->editSnapshot;
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['className'] = 'editSnapshot';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['editSnapshot']['url'] = array('module' => 'zanode', 'method' => 'editSnapshot', 'params' => 'snapshotID={id}');
|
||||
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['restoreSnapshot']['icon'] = 'restart';
|
||||
$config->zanode->snapshotDtable->fieldList['actions']['list']['restoreSnapshot']['hint'] = $lang->zanode->restoreSnapshot;
|
||||
|
||||
@@ -33,10 +33,10 @@ $config->zanode->form->createsnapshot = array();
|
||||
$config->zanode->form->createsnapshot['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim');
|
||||
$config->zanode->form->createsnapshot['desc'] = array('type' => 'string', 'required' => false, 'control' => 'editor');
|
||||
|
||||
$config->zanode->form->editSnapshot = array();
|
||||
$config->zanode->form->editSnapshot['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim');
|
||||
$config->zanode->form->editSnapshot['desc'] = array('type' => 'string', 'required' => false, 'control' => 'editor');
|
||||
$config->zanode->form->editsnapshot = array();
|
||||
$config->zanode->form->editsnapshot['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim');
|
||||
$config->zanode->form->editsnapshot['desc'] = array('type' => 'string', 'required' => false, 'control' => 'editor');
|
||||
|
||||
$config->zanode->form->ajaxUpdateImage = array();
|
||||
$config->zanode->form->ajaxUpdateImage['status'] = array('type' => 'string', 'required' => false);
|
||||
$config->zanode->form->ajaxUpdateImage['path'] = array('type' => 'string', 'required' => false);
|
||||
$config->zanode->form->ajaxupdateimage = array();
|
||||
$config->zanode->form->ajaxupdateimage['status'] = array('type' => 'string', 'required' => false);
|
||||
$config->zanode->form->ajaxupdateimage['path'] = array('type' => 'string', 'required' => false);
|
||||
|
||||
@@ -311,7 +311,10 @@ class zanode extends control
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$this->zanode->editSnapshot($snapshotID);
|
||||
$formData = form::data()->get();
|
||||
if(is_numeric($formData->name)) return $this->sendError(array('name' => sprintf($this->lang->error->code, $this->lang->zanode->name)));
|
||||
|
||||
$this->zanode->editSnapshot($snapshotID, $formData);
|
||||
if(dao::isError()) return $this->sendError(dao::getError());
|
||||
|
||||
$this->loadModel('action')->create('zanode', $snapshot->host, 'editSnapshot', '', $snapshot->localName ? $snapshot->localName : $snapshot->name);
|
||||
|
||||
+6
-13
@@ -191,22 +191,16 @@ class zanodemodel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Snapshot.
|
||||
* 编辑快照。
|
||||
* Edit snapshot.
|
||||
*
|
||||
* @param int $snapshotID
|
||||
* @param int $snapshotID
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
public function editSnapshot($snapshotID)
|
||||
public function editSnapshot(int $snapshotID, object $data): void
|
||||
{
|
||||
$data = form::data()->get();
|
||||
|
||||
if(empty($data->name)) dao::$errors['name'] = $this->lang->zanode->imageNameEmpty;
|
||||
if(dao::isError()) return false;
|
||||
|
||||
if(is_numeric($data->name)) dao::$errors['name'] = sprintf($this->lang->error->code, $this->lang->zanode->name);
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$newSnapshot = new stdClass();
|
||||
$newSnapshot->localName = $data->name;
|
||||
$newSnapshot->desc = $data->desc;
|
||||
@@ -216,7 +210,6 @@ class zanodemodel extends model
|
||||
->where('id')->eq($snapshotID)
|
||||
->autoCheck()
|
||||
->exec();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
|
||||
title=测试 zanodeModel->editSnapshot().
|
||||
cid=1
|
||||
|
||||
- 测试编辑快照
|
||||
- 属性name @defaultSnap
|
||||
- 属性localName @test
|
||||
- 属性desc @test
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/zanode.class.php';
|
||||
|
||||
zdTable('image')->config('image')->gen(1);
|
||||
zdTable('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
$snapshot = new stdclass();
|
||||
$snapshot->name = 'test';
|
||||
$snapshot->desc = 'test';
|
||||
|
||||
$zanode = new zanodeTest();
|
||||
r($zanode->editSnapshotTest(1, $snapshot)) && p('name,localName,desc') && e('defaultSnap,test,test'); //测试编辑快照
|
||||
@@ -154,4 +154,21 @@ class zanodeTest
|
||||
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_IMAGE)->where('id')->eq($snapshotID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试编辑快照。
|
||||
* Test edit snapshot.
|
||||
*
|
||||
* @param int $snapshotID
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function editSnapshotTest(int $snapshotID, object $data): object|array
|
||||
{
|
||||
$this->editSnapshot($snapshotID, $data);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_IMAGE)->where('id')->eq($snapshotID)->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user