fieldResetter plugin update
3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: September 28, 2016 (RSS)
Hi All,
When Carl Crowder was working for Interactive Tools he created a handy fieldResetter plugin which doesn’t seem to work in the latest versions of CMSBuilder
Has anyone updated the plugin and could they share the result?
The original code is below.
Thanks,
Jerry Kornbluth
<?php
/*
Plugin Name: Field Resetter
Description: Adds an advanced command to section list views to reset a field on all records
Version: 1.00
Requires at least: 2.03
*/
// Add the names of tables and fields, and the value to reset them to, to the following array.
// For example, to add a command to set the field 'available' to '0' on the table 'products'
// would look like this:
// $GLOBALS['FIELD_RESET_FIELDS'] = array(
// array( 'tableName' => 'products', 'fieldName' => 'available', 'resetValue' => 0 )
// );
$GLOBALS['FIELD_RESET_FIELDS'] = array(
array('tableName' => 'accounts', 'fieldName' => 'first_time_login', 'resetValue' => 1 )
);
// DON'T UPDATE ANYTHING BELOW THIS LINE
addFilter( 'list_advancedCommands', '_fieldReset_addCommands', null, 1 );
addAction( 'section_unknownAction', '_fieldReset_handleReset', null, 2 );
addAction( 'init_complete', '_fieldReset_modal', null, null );
function _fieldReset_addCommands( $labelsToValues ) {
global $CURRENT_USER;
if ( !$CURRENT_USER['isAdmin'] ) return;
$tableName = $_REQUEST['menu'];
$i=0;
foreach( $GLOBALS['FIELD_RESET_FIELDS'] as $field ) {
if ( $field['tableName'] == $tableName ) {
$label = "Set '{$field['fieldName']}' on all records to {$field['resetValue']}";
$labelsToValues[ $label ] = "reset_" . $i;
}
$i++;
}
return $labelsToValues;
}
function _fieldReset_handleReset( $tableName, $action ) {
if ( strpos( $action, 'reset' ) !== 0 ) return;
$parts = preg_split( '!_!', $action );
$field = $GLOBALS['FIELD_RESET_FIELDS'][ (int)$parts[1] ];
global $TABLE_PREFIX;
$query = "UPDATE {$TABLE_PREFIX}{$field['tableName']} SET {$field['fieldName']} = '" . mysql_escape( $field['resetValue'] ) . "'";
mysql_query( $query ) or die( mysql_error() );
header( 'Location: admin.php?_fieldReset=' . $field['fieldName'] . '&menu=' . $tableName );
}
function _fieldReset_modal() {
if ( @$_REQUEST['_fieldReset'] ) {
global $APP;
$APP['notices'] = 'All ' . $_REQUEST['_fieldReset'] . ' values reset';
}
}
?>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By ross - September 28, 2016
Hi Jerry
Thanks for posting.
We can update the plugin for you through consulting. To get started on that, just send me an email via consulting@interactivetools.com
Another option: do you have the Developer Console plugin? If you are comfortable with SQL, you can use the MySQL console to update/reset all the values for a field in a table.
Here's a link to the plugin: http://www.interactivetools.com/add-ons/developer-console/
Let me know any questions.
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Hi Ross,
I've used mysql, but don't want to have my client's try to do that.
I don't use the plugin too often, but was hoping that someone had already updated it.
Unless you have some quick pointers, I'm afraid that consulting will have to wait.
Thanks for looking at this though,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php