Commit 3ca88260 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #4292 Migrated faiPartition to simplePlugin

parent 8ba57639
......@@ -28,9 +28,12 @@ class PartitionDialog extends GenericDialog
protected $initialDialogValue = NULL;
protected $plugin;
function __construct($simplePlugin, &$attribute, $partition = array())
{
$this->attribute = $attribute;
$this->attribute = $attribute;
$this->plugin = $simplePlugin;
$this->dialog = new $this->dialogClass($simplePlugin->config, $partition, $simplePlugin, $simplePlugin->FAIdiskType);
$base = $simplePlugin->dn;
......@@ -57,7 +60,7 @@ class PartitionDialog extends GenericDialog
$msgs = $this->dialog->check();
if (!count($msgs)) {
$new_partition = $this->dialog->save();
$msgs = $this->attribute->plugin->check_disks($new_partition);
$msgs = $this->plugin->check_disks($new_partition);
}
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
......@@ -106,8 +109,8 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
if (isset($value['bootable']) && $value['bootable']) {
$opt[] = _('bootable');
}
if (isset($value['preserve']) && $value['preserve']) {
$opt[] = _('preserve').':'.$value['preserveType'];
if (!empty($value['preserve'])) {
$opt[] = _('preserve').':'.$value['preserve'];
}
return array(
$value['description'],
......@@ -286,6 +289,7 @@ class faiDiskEntry extends simplePlugin
$this->cn = $disk['cn'];
$this->description = $disk['description'];
$this->attributesAccess['cn']->setInitialValue($this->cn);
/* Get devices used in volume base disks */
$this->attributesAccess['lvmDevices']->attribute->setChoices($this->getAvailablePartitions());
......@@ -330,8 +334,7 @@ class faiDiskEntry extends simplePlugin
$preserve = preg_split('/,/', $m[1], -1, PREG_SPLIT_NO_EMPTY);
foreach ($preserve as $presflag) {
if (isset($disk['partitions'][$presflag])) {
$disk['partitions'][$presflag]['preserve'] = TRUE;
$disk['partitions'][$presflag]['preserveType'] = 'always';
$disk['partitions'][$presflag]['preserve'] = 'always';
}
}
continue;
......@@ -341,8 +344,7 @@ class faiDiskEntry extends simplePlugin
$preserve = preg_split('/,/', $m[1], -1, PREG_SPLIT_NO_EMPTY);
foreach ($preserve as $presflag) {
if (isset($disk['partitions'][$bootflag])) {
$disk['partitions'][$presflag]['preserve'] = TRUE;
$disk['partitions'][$presflag]['preserveType'] = 'reinstall';
$disk['partitions'][$presflag]['preserve'] = 'reinstall';
}
}
continue;
......@@ -434,16 +436,16 @@ class faiDiskEntry extends simplePlugin
if (isset($part['resize']) && $part['resize']) {
$resize .= $id.',';
}
if (isset($part['preserve']) && $part['preserve']) {
if ($part['preserveType'] == 'always') {
if (isset($part['preserve'])) {
if ($part['preserve'] == 'always') {
$preserve_always .= $id.',';
} else {
} elseif ($part['preserve'] == 'reinstall') {
$preserve_reinstall .= $id.',';
}
}
/* Unset non valid attributes */
foreach (array('bootable','encrypted','preserve','preserveType','resize','FAIdiskType') as $attr) {
foreach (array('bootable','encrypted','preserve','resize','FAIdiskType') as $attr) {
if (isset($tmp['partitions'][$id][$attr])) {
unset($tmp['partitions'][$id][$attr]);
}
......@@ -513,5 +515,36 @@ class faiDiskEntry extends simplePlugin
}
return $ret;
}
/* Checks the disk combinations */
function check_disks($disk_to_add = array())
{
$msgs = array();
/* Check 'disk' combinations.
* - There can be four primary partitions.
* - If there is at least one 'logical' partition, then there can be only
* three 'primary' partitions.
*/
if ($this->FAIdiskType == 'disk') {
$types = array('logical' => array(), 'primary' => array());
$types[$disk_to_add['FAIpartitionType']][$disk_to_add['FAIpartitionNr']] = 1;
foreach ($this->partitions as $key => $part) {
$types[$part['FAIpartitionType']][$part['FAIpartitionNr']] = 1;
}
// There can only be four primary partitions per disk - without any logical partition.
if (count($types['logical']) == 0) {
if (count($types['primary']) > 4) {
$msgs[] = _('You have more than four primary partition table entries in your configuration');
}
} else {
if (count($types['primary']) > 3) {
$msgs[] = _('You cannot have more than three primary partition while using logical partitions');
}
}
}
return $msgs;
}
}
?>
This diff is collapsed.
......@@ -265,6 +265,7 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
if (isset($disk['rename'])) {
unset($this->value[$disk['rename']['from']]);
$disk['cn'] = $disk['rename']['to'];
unset($disk['rename']);
}
$this->value[$disk['cn']] = $disk;
......
<h2>{t}Partition{/t}</h2>
<table style='width: 100%;' width="100%">
<tr>
{if $FAIdiskType == "lvm"}
<td>{t}Name{/t}</td>
<td width="35%">
<input type='text' name="cn" value="{$cn}">
</td>
{else}
<td>{t}Type{/t}</td>
<td width="35%">
<select name="FAIpartitionType" onChange='document.mainform.submit();'>
{html_options options=$partitionTypes selected=$FAIpartitionType}
</select>
{if $cn != ""}&nbsp;({$cn}){/if}
</td>
{/if}
<td>{t}Description{/t}</td>
<td width="35%">
<input type="text" value="{$description}" name="description">
</td>
</tr>
{if $FAIdiskType == "disk" || $FAIdiskType == "lvm"}
<tr>
<td>{t}Size{/t}</td>
<td colspan=3>
<select name="FAIpartitionSizeType" onChange='document.mainform.submit();'>
{html_options options=$partitionSizeTypes selected=$FAIpartitionSizeType}
</select>
{if $FAIpartitionSizeType != "remaining"}
<input type='text' name='sizeStart' value='{$sizeStart}' size='5'>
<select name='sizeStart_Type'>
{html_options options=$sizeTypes selected=$sizeStart_Type}
</select>
{else}
<input type='text' name='dummy3' value='' size='5' disabled>
<select name='dummy4' disabled>
{html_options options=$sizeTypes}
</select>
{/if}
&nbsp;-&nbsp;
{if $FAIpartitionSizeType != "fixed" && $FAIpartitionSizeType != "remaining"}
<input type='text' name='sizeStop' value='{$sizeStop}' size='5'>
<select name='sizeStop_Type'>
{html_options options=$sizeTypes selected=$sizeStop_Type}
</select>
{else}
<input type='text' name='dummy1' value='' size='5' disabled>
<select name='dummy2' disabled>
{html_options options=$sizeTypes}
</select>
{/if}
</td>
</tr>
<tr>
<td colspan="4">
<p class="seperator">&nbsp;</p>
</td>
</tr>
<tr>
<td colspan="2">
<input id="resize" type='checkbox' value='1' name='resize' {if $resize} checked {/if}>
&nbsp;<label for='resize'>{t}Resize existing partition{/t}</label>
</td>
<td colspan="2">
<input id="bootable" type='checkbox' value='1' name='bootable' {if $bootable} checked {/if}>
&nbsp;<label for='bootable'>{t}Bootable{/t}</label>
</td>
</tr>
<tr>
<td colspan="4">
<input id="preserve" type='checkbox' value='1' name='preserve' {if $preserve} checked {/if}>
&nbsp;<label for="preserve">{t}Preserve{/t}</label>
<select name='preserveType'>
{html_options options=$preserveTypes selected=$preserveType}
</select>
</td>
</tr>
{/if}
<tr>
<td colspan="4">
<p class="seperator">&nbsp;</p>
</td>
</tr>
{if $FAIdiskType == "raid"}
<tr>
<td colspan="4">
<h2>{t}Combined physical partitions{/t}</h2>
<select name='physicalPartition[]' size=5 style="width:100%; font-family: monospace;"
multiple>
{html_options options=$plist}
</select>
<br>
<select name='physicalPartitionAdd' style='width:240px;'>
{html_options options=$physicalPartitionList}
</select>
<input type="submit" name='addPhysicalPartition' value="{msgPool type="addButton"}">&nbsp;
<input type="submit" name='delPhysicalPartition' value="{msgPool type="delButton"}">&nbsp;
<input type="submit" name='toggleMissing' value="{t}Toggle missing{/t}">&nbsp;
<input type="submit" name='toggleSpare' value="{t}Toggle spare{/t}">&nbsp;
</td>
</tr>
<tr>
<td colspan="4">
<p class="seperator">&nbsp;</p>
</td>
</tr>
{/if}
<tr>
<td>
{t}Filesystem{/t}
</td>
<td>
<select name='FAIfsType' onChange="document.mainform.submit();">
{html_options options=$FAIfsTypes selected=$FAIfsType}
</select>
</td>
<td>
{t}Filesystem create options{/t}
</td>
<td>
<input type='text' name="FAIfsCreateOptions" value="{$FAIfsCreateOptions}">
</td>
</tr>
<tr>
<td colspan=2>
<input id="encrypted" type='checkbox' name='encrypted' value='1' {if $encrypted} checked {/if}>
&nbsp;<label for="encrypted">{t}Encrypted{/t}</label>
</td>
<td>
{t}Tune options{/t}
</td>
<td>
<input type='text' name="FAIfsTuneOptions" value="{$FAIfsTuneOptions}">
</td>
</tr>
<tr>
<td colspan="4">
<p class="seperator">&nbsp;</p>
</td>
</tr>
<tr>
<td>
{t}Mount point{/t}
</td>
<td>
{if $FAIfsType != "swap"}
<input type='text' name="FAImountPoint" value="{$FAImountPoint}">
{else}
<input type='text' name="dummy10" value="swap" disabled>
{/if}
</td>
<td>
{t}Mount options{/t}
</td>
<td>
<input type='text' name="FAImountOptions" value="{$FAImountOptions}">
</td>
</tr>
<!-- Table cell sizing -->
<tr>
<td colspan=2 style='width:50%;'></td>
<td colspan=2 style='width:50%;'></td>
</tr>
</table>
<input type='hidden' name='faiPartition' value='1'>
<p class='seperator'>&nbsp;</p>
<div style='text-align:right; width:100%; padding:5px'>
<input type='submit' name='PartitionSave' value='{msgPool type=okButton}'>
<input type='submit' name='PartitionCancel' value='{msgPool type=cancelButton}'>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment