Skip to content

Commit

Permalink
Use BEGIN/COMMIT transaction on each upgrade block
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Dec 14, 2016
1 parent b923c5e commit efd6c79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion inc/_core/model/db/_db.class.php
Expand Up @@ -1537,7 +1537,7 @@ function dump_queries( $html = true )




/** /**
* BEGIN A TRANSCATION * BEGIN A TRANSACTION
* *
* Note: By default, MySQL runs with autocommit mode enabled. * Note: By default, MySQL runs with autocommit mode enabled.
* This means that as soon as you execute a statement that updates (modifies) * This means that as soon as you execute a statement that updates (modifies)
Expand Down
24 changes: 11 additions & 13 deletions install/_functions_evoupgrade.php
Expand Up @@ -85,6 +85,10 @@ function upg_task_start( $version, $title = '' )
task_begin( $title ); task_begin( $title );
} }


// Begin a transaction for the upgrade block:
global $DB;
$DB->begin();

return true; return true;
} }
else else
Expand All @@ -106,6 +110,10 @@ function upg_task_end( $print_result = true )
if( ! empty( $upgrade_db_version ) ) if( ! empty( $upgrade_db_version ) )
{ // Only if the upgrade task is not ended yet: { // Only if the upgrade task is not ended yet:


// End current transaction of the upgrade block:
global $DB;
$DB->commit();

if( $print_result ) if( $print_result )
{ // Print out the end of task: { // Print out the end of task:
task_end(); task_end();
Expand Down Expand Up @@ -7613,7 +7621,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order


if( upg_task_start( 12005, 'Update widget container "Item Single"...' ) ) if( upg_task_start( 12005, 'Update widget container "Item Single"...' ) )
{ // part of 6.8.0-alpha { // part of 6.8.0-alpha
$DB->begin();
$SQL = new SQL( 'Get all collections that have a widget container "Item Single"' ); $SQL = new SQL( 'Get all collections that have a widget container "Item Single"' );
$SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' ); $SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' );
$SQL->FROM( 'T_widget' ); $SQL->FROM( 'T_widget' );
Expand Down Expand Up @@ -7665,7 +7672,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
$DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code ) $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code )
VALUES '.implode( ', ', $item_attachments_widget_rows ) ); VALUES '.implode( ', ', $item_attachments_widget_rows ) );
} }
$DB->commit();
upg_task_end(); upg_task_end();
} }


Expand Down Expand Up @@ -7821,8 +7827,7 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
} }


if( upg_task_start( 12085, 'Update widget container "Item Single"...' ) ) if( upg_task_start( 12085, 'Update widget container "Item Single"...' ) )
{ // part of 6.8.0-alpha { // part of 6.8.0-alpha
$DB->begin();
$SQL = new SQL( 'Get all collections that have a widget container "Item Single"' ); $SQL = new SQL( 'Get all collections that have a widget container "Item Single"' );
$SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' ); $SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' );
$SQL->FROM( 'T_widget' ); $SQL->FROM( 'T_widget' );
Expand Down Expand Up @@ -7882,7 +7887,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
$DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code ) $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code )
VALUES '.implode( ', ', $item_tags_widget_rows ) ); VALUES '.implode( ', ', $item_tags_widget_rows ) );
} }
$DB->commit();
upg_task_end(); upg_task_end();
} }


Expand Down Expand Up @@ -7917,8 +7921,7 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
} }


if( upg_task_start( 12100, 'Update widget container "Item Single" by adding "Item Location" widget...' ) ) if( upg_task_start( 12100, 'Update widget container "Item Single" by adding "Item Location" widget...' ) )
{ // part of 6.8.0-alpha { // part of 6.8.0-alpha
$DB->begin();
$SQL = new SQL( 'Get all collections that have a widget container "Item Single"' ); $SQL = new SQL( 'Get all collections that have a widget container "Item Single"' );
$SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' ); $SQL->SELECT( 'wi_ID, wi_coll_ID, wi_code, wi_order' );
$SQL->FROM( 'T_widget' ); $SQL->FROM( 'T_widget' );
Expand Down Expand Up @@ -7977,7 +7980,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
$DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code ) $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code )
VALUES '.implode( ', ', $item_locations_widget_rows ) ); VALUES '.implode( ', ', $item_locations_widget_rows ) );
} }
$DB->commit();
upg_task_end(); upg_task_end();
} }


Expand Down Expand Up @@ -8019,7 +8021,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
db_add_col( 'T_locales', 'loc_input_timefmt', 'varchar(20) COLLATE ascii_general_ci NOT NULL default "H:i:s" AFTER loc_shorttimefmt' ); db_add_col( 'T_locales', 'loc_input_timefmt', 'varchar(20) COLLATE ascii_general_ci NOT NULL default "H:i:s" AFTER loc_shorttimefmt' );


// Allow only numeric date formats: // Allow only numeric date formats:
$DB->begin();
$SQL = new SQL( 'Get all short date formats"' ); $SQL = new SQL( 'Get all short date formats"' );
$SQL->SELECT( 'loc_locale, loc_datefmt, loc_timefmt' ); $SQL->SELECT( 'loc_locale, loc_datefmt, loc_timefmt' );
$SQL->FROM( 'T_locales' ); $SQL->FROM( 'T_locales' );
Expand All @@ -8039,13 +8040,11 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
loc_input_timefmt = "H:i:s" loc_input_timefmt = "H:i:s"
WHERE loc_locale = '.$DB->quote( $loc_data['loc_locale'] ) ); WHERE loc_locale = '.$DB->quote( $loc_data['loc_locale'] ) );
} }
$DB->commit();
upg_task_end(); upg_task_end();
} }


if( upg_task_start( 12130, 'Create new widget container "Item Single Header"...' ) ) if( upg_task_start( 12130, 'Create new widget container "Item Single Header"...' ) )
{ // part of 6.8.0-alpha { // part of 6.8.0-alpha
$DB->begin();
$SQL = new SQL( 'Get all collections that have a widget container "Item Single"' ); $SQL = new SQL( 'Get all collections that have a widget container "Item Single"' );
$SQL->SELECT( 'wi_ID, wi_coll_ID, wi_order, wi_enabled, wi_code, wi_params, blog_type' ); $SQL->SELECT( 'wi_ID, wi_coll_ID, wi_order, wi_enabled, wi_code, wi_params, blog_type' );
$SQL->FROM( 'T_widget' ); $SQL->FROM( 'T_widget' );
Expand Down Expand Up @@ -8079,7 +8078,6 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
$DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code, wi_params ) $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_code, wi_params )
VALUES '.implode( ', ', $item_info_line_widget_rows ) ); VALUES '.implode( ', ', $item_info_line_widget_rows ) );
} }
$DB->commit();
upg_task_end(); upg_task_end();
} }


Expand Down

0 comments on commit efd6c79

Please sign in to comment.