Skip to content

Commit

Permalink
Improve efficiency of processing
Browse files Browse the repository at this point in the history
- show message if there is no project selected
- keep old message to cover the case only if projects is selected (optimized)
- fixed coding standards

Fixes #21927
  • Loading branch information
jllano authored and vboctor committed Dec 29, 2016
1 parent 900469d commit 0824a88
Showing 1 changed file with 78 additions and 73 deletions.
151 changes: 78 additions & 73 deletions admin/move_attachments.php
Expand Up @@ -257,28 +257,6 @@ function move_attachments_to_disk( $p_type, array $p_projects ) {
return $t_moved;
}

$t_moved = array();

if ( null != $f_project_to_move ) {
foreach ( $f_project_to_move as $t_project_to_move) {

$t_array = explode( ':', $t_project_to_move );

if( isset( $t_array[1] ) ) {
$f_project_id = $t_array[1];

switch( $t_array[0] ) {
case 'disk':
$t_moved[] = move_attachments_to_disk( $f_file_type, array( $f_project_id ) );
break;
case 'db':
$t_moved[] = move_attachments_to_db( $f_file_type, array( $f_project_id ) );
break;
}
}
}
}

form_security_purge( 'move_attachments_project_select' );

# Page header, menu
Expand All @@ -293,68 +271,95 @@ function move_attachments_to_disk( $p_type, array $p_projects ) {

<?php

# Display results
if( empty( $t_moved ) ) {
if( null == $f_project_to_move ) {
echo '<div class="alert alert-danger">';
echo '<p class="lead"><strong>Opps!</strong> Please select the project you want to move the attachment.</p>';
echo '<p class="lead"><strong>Opps!</strong> Please select the project you want to move the attachment.</p>';
echo '</div>';
} else {
foreach( $t_moved as $t_row ) {
$t_row = $t_row[0];

echo '<div class="widget-box widget-color-blue2">';
echo '<div class="widget-header widget-header-small">';
echo '<h4 class="widget-title lighter">';
echo '<i class="ace-icon fa fa-paperclip"></i>';
printf(
"Project '%s' : %d attachments %s",
$t_row['name'],
$t_row['rows'],
( 0 == $t_row['failed']
? 'moved successfully'
: 'to move, ' . $t_row['failed'] . ' failures') );
echo '</h4>';

$t_moved = array();

foreach( $f_project_to_move as $t_project_to_move ) {

$t_array = explode( ':', $t_project_to_move );

if( isset( $t_array[1] ) ) {
$t_project_id = $t_array[1];

switch( $t_array[0] ) {
case 'disk':
$t_moved[] = move_attachments_to_disk( $f_file_type, array( $t_project_id ) );
break;
case 'db':
$t_moved[] = move_attachments_to_db( $f_file_type, array( $t_project_id ) );
break;
}
}
}

# Display results
if( empty( $t_moved ) ) {
echo '<div class="alert alert-danger">';
echo '<p class="lead">Nothing to do.</p>';
echo '</div>';
echo '<div class="widget-body">';
echo '<div class="widget-main no-padding">';
if( is_array( $t_row['data'] ) ) {
# Display details of moved attachments
echo '<div class="table-responsive">';
echo '<table class="table table-bordered table-condensed">';
echo '<thead>';
echo '<tr>',
$f_file_type == 'bug' ? '<td width="5%">Bug ID</td>' : '',
'<td width="3%">File ID</td><th width="15%">Filename</td><td width="25%">Status</td>',
'</tr>';
echo '</thead>';
echo '<tbody>';
foreach( $t_row['data'] as $t_data ) {
echo '<tr>';
if( $f_file_type == 'bug' ) {
printf( '<td>%s</td>', bug_format_id( $t_data['bug_id'] ) );
} else {
foreach( $t_moved as $t_row ) {
$t_row = $t_row[0];

echo '<div class="widget-box widget-color-blue2">';
echo '<div class="widget-header widget-header-small">';
echo '<h4 class="widget-title lighter">';
echo '<i class="ace-icon fa fa-paperclip"></i>';
printf(
"Project '%s' : %d attachments %s",
$t_row['name'],
$t_row['rows'],
( 0 == $t_row['failed']
? 'moved successfully'
: 'to move, ' . $t_row['failed'] . ' failures') );
echo '</h4>';
echo '</div>';
echo '<div class="widget-body">';
echo '<div class="widget-main no-padding">';
if( is_array( $t_row['data'] ) ) {
# Display details of moved attachments
echo '<div class="table-responsive">';
echo '<table class="table table-bordered table-condensed">';
echo '<thead>';
echo '<tr>',
$f_file_type == 'bug' ? '<td width="5%">Bug ID</td>' : '',
'<td width="3%">File ID</td><th width="15%">Filename</td><td width="25%">Status</td>',
'</tr>';
echo '</thead>';
echo '<tbody>';
foreach( $t_row['data'] as $t_data ) {
echo '<tr>';
if( $f_file_type == 'bug' ) {
printf( '<td>%s</td>', bug_format_id( $t_data['bug_id'] ) );
}
printf( '<td>%s</td><td>%s</td><td>%s</td></tr>',
$t_data['id'],
$t_data['filename'],
$t_data['status'] );
}
printf( '<td>%s</td><td>%s</td><td>%s</td></tr>',
$t_data['id'],
$t_data['filename'],
$t_data['status'] );
echo '</tbody>';
echo '</table>';
echo '</div>';

} else {
# No data rows - display error message
echo '<div class="alert alert-danger">';
echo '<p>' . $t_row['data'] . '</p>';
echo '</div>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';

} else {
# No data rows - display error message
echo '<div class="alert alert-danger">';
echo '<p>' . $t_row['data'] . '</p>';
echo '</div>';
echo '</div>';
echo '<br/>';
}
echo '</div>';
echo '</div>';
echo '</div>';
echo "<br/>";
}
}
echo "<br/>";
echo '<br/>';
print_link_button( 'system_utils.php', 'Back to System Utilities' );

echo '</div>';
Expand Down

0 comments on commit 0824a88

Please sign in to comment.