Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 static function searchreplaceinObjectProperties($object, $search, $replace)
 {
     if (is_array($object)) {
         foreach ($object as $k => $v) {
             $object[$k] = AECToolbox::searchreplaceinObjectProperties($v, $search, $replace);
         }
     } elseif (is_object($object)) {
         foreach (get_object_vars($object) as $field => $v) {
             if (strpos($field, '_') !== 0) {
                 $object->{$field} = AECToolbox::searchreplaceinObjectProperties($object->{$field}, $search, $replace);
             }
         }
     } else {
         $object = str_replace($search, $replace, $object);
     }
     return $object;
 }