1
0
Fork 0

Add untested import functionality for transitioning from existing screens system.

This commit is contained in:
Andrew Tomaka 2011-11-10 15:52:45 -05:00
parent c3e73a06aa
commit 97b3ca7a11
5 changed files with 180 additions and 0 deletions

View file

@ -0,0 +1,98 @@
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Import extends CI_Controller {
public function index() {
$this->load->model('fileupload');
$total_uploads = $this->fileupload->count_uploads();
if($total_uploads == 0) {
$this->template->load('template','/import/index');
} else {
$this->template->load('template','/import/onetime');
}
}
public function process() {
$old_uploads = '/home/ncaguild/nca-guild.com/screens/old_uploads/';
$new_uploads = '/home/ncaguild/nca-guild.com/screens/uploads/';
// load all file
$uploads = scandir($old_uploads);
$this->load->model('fileupload');
$data['uploads'] = array();
// foreach file
foreach($uploads as $upload) {
// if it is formatted correctly
if(preg_match('/^([0-9]+)(\..*)/', $upload, $matches) != 0) continue;
$extension = $matches[1];
$old_id = $matches[0];
$size = getimagesize($old_uploads . $upload);
$width = $size[0];
$height = $size[1];
$file_size = filesize($old_uploads . $upload) / 1024;
$hash = md5_file($old_uploads . $upload);
$duplicate = $this->fileupload->check_duplicate($hash);
if($file_size > 2048) {
$data['uploads'][] = array(
'old' => $upload,
'error' => 'File size exceeds 2048kb',
);
continue;
}
if(preg_match('/(gif|jpg|jpeg|png|bmp)/',$upload) == 0) {
$data['uploads'][] = array(
'old' => $upload,
'error' => 'File extension not supported',
);
continue;
}
if($duplicate) {
$data['uploads'][] = array(
'old' => $upload,
'error' => 'File is a duplicate of id <b>'. $duplicate . '</b>',
);
continue;
}
// add a row to the database
$file_name = $this->fileupload->add_upload($extension, 'unknown', $width, $height, $file_size, $hash);
// copy in case we screwed up and can fix later
copy($old_uploads . $upload, $new_uploads . $file_name . $extension);
// create the new thumbmail
$config = array(
'image_library' => 'gd2',
'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'],
'create_thumb' => true,
'maintain_ratio' => true,
'width' => 175,
'height' => 175,
'new_image' => './thumbs/' . $file_name . $upload['file_ext'],
'thumb_marker' => '',
);
$this->load->library('image_lib',$config);
$this->image_lib->resize();
$data['uploads'][] = array(
'old' => $upload,
'new_id' => $new_id,
'height' => $height,
'width' => $width,
'file_size' => $file_size,
'hash' => $hash,
'extension' => $extension,
);
}
$this->load->vars($data);
$this->template->load('template','/import/complete');
}
}
?>

View file

@ -0,0 +1,32 @@
<div id="message">
<table width="100%" id="uploadTable">
<tr>
<th>File Name</th>
<th>New ID</th>
<th>Dimensions</th>
<th>File Size</th>
<th>Hash</th>
<th>Extension</th>
</tr>
<?php foreach($uploads as $upload) { ?>
<tr>
<td>
<span class"<?php echo array_key_exists('error',$upload) ? 'error' : 'success'; ?>">
<?php echo $upload['old']; ?>
</span>
</td>
<?php if(array_key_exists('error',$upload)) { ?>
<td colspan="5">
<?php echo $upload['error']; ?>
</td>
<?php } else { ?>
<td><?php echo $upload['new_id']; ?></td>
<td><?php echo $upload['width']; ?>x<?php echo $upload['height']; ?></td>
<td><?php echo $upload['file_size']; ?>kb</td>
<td><?php echo $upload['hash']; ?></td>
<td><?php echo $upload['extension']; ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>

View file

@ -0,0 +1,8 @@
<div style="margin:auto; top: 150px;" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-dialog-title-dialog" class="ui-dialog-title">Confirmation</span>
</div>
<div style="width: auto;" class="ui-dialog-content ui-widget-content" id="dialog">
<p>Are you sure you are ready to import? <a href="<?php echo base_url('/import/process'); ?>" style="text-decoration: underline">Yes</a>!</p>
</div>
</div>

View file

@ -0,0 +1,8 @@
<div style="margin:auto; top: 150px;" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-dialog-title-dialog" class="ui-dialog-title">Confirmation</span>
</div>
<div style="width: auto;" class="ui-dialog-content ui-widget-content" id="dialog">
<p>You cannot import to a database that has existing data.</p>
</div>
</div>

View file

@ -369,4 +369,38 @@ h1{
.underline { .underline {
text-decoration: underline; text-decoration: underline;
}
/*-------------------------
Import
--------------------------*/
#uploadTable {
border-collapse: collapse;
border: 2px solid black;
margin-left: auto;
margin-right: auto;
}
#uploadTable th {
font-weight: bold;
border: 2px solid black;
padding: 5px;
}
#uploadTable td {
border: 2px solid black;
padding: 1px;
}
.error {
color: red;
}
.success {
color: green;
} }