public function Action() { if (empty($_POST['type']) || empty($_POST['search'])) { return "<h3>Incomplete Query.</h3>"; } $db = JFactory::getDBO(); $types = array('config' => array('config', 'aecConfig'), 'processor' => array('config_processors', 'PaymentProcessor'), 'coupons' => array('coupons', 'Coupon'), 'displaypipeline' => array('displaypipeline', 'displayPipeline'), 'eventlog' => array('eventlog', 'eventLog'), 'invoice' => array('invoices', 'Invoice'), 'itemgroups' => array('itemgroups', 'ItemGroup'), 'history' => array('log_history', 'logHistory'), 'metauser' => array('metauser', 'metaUserDB'), 'mi' => array('microintegrations', 'microIntegration'), 'plans' => array('plans', 'SubscriptionPlan'), 'subscr' => array('subscr', 'Subscription')); $changes = 0; foreach ($_POST['type'] as $type) { $query = 'SELECT `id` FROM `#__acctexp_' . $types[$type][0] . '`'; $db->setQuery($query); $ids = xJ::getDBArray($db); foreach ($ids as $id) { $objclass = $types[$type][1]; $obj = new $objclass(); $obj->load($id); if (!empty($_POST['armed']) && !empty($_POST['replace'])) { if (AECToolbox::searchinObjectProperties($obj, $_POST['search'])) { $mod = AECToolbox::searchreplaceinObjectProperties($obj, $_POST['search'], $_POST['replace']); $mod->check(); $mod->store(); $changes++; } } else { if (AECToolbox::searchinObjectProperties($obj, $_POST['search'])) { $changes++; } } } } $return = ''; $return .= "<h3>Query Result:</h3>"; $return .= "<p>Searching for <strong>" . $_POST['search'] . "</strong></p>"; $return .= "<p>Replacing it with <strong>" . $_POST['replace'] . "</strong></p>"; $return .= "<p>Found <strong>" . $changes . "</strong> database entries.</p>"; if ($_POST['armed']) { $return .= "<p>Modified <strong>" . $changes . "</strong> database entries.</p>"; } return $return; }
static function searchinObjectProperties($object, $search) { $found = false; if (is_array($object)) { foreach ($object as $k => $v) { $found += AECToolbox::searchinObjectProperties($v, $search); } } elseif (is_object($object)) { foreach (get_object_vars($object) as $field => $v) { if (strpos($field, '_') !== 0) { $found += AECToolbox::searchinObjectProperties($object->{$field}, $search); } } } else { $found += substr_count($object, $search); } return $found; }