startTransaction() public static method

public static startTransaction ( )
Ejemplo n.º 1
0
 public function duplicate($id)
 {
     DB::startTransaction();
     if (!DB::query("insert into " . $this->tableName() . " (name, user_id, url) select concat(name,' copy') as name, user_id, url from " . $this->tableName() . " where cloaker_id='" . DB::quote($id) . "'")) {
         DB::rollback();
         return false;
     }
     $new_id = DB::insertId();
     if (!$new_id) {
         DB::rollback();
         return false;
     }
     if (!CloakerOptionModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CloakerHostnameModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CloakerIpModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CloakerRefererModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CloakerUaModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     DB::commit();
     return $new_id;
 }
Ejemplo n.º 2
0
 function test_3_transaction_rollback_all()
 {
     DB::$nested_transactions = true;
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 200, 'Abe');
     $depth = DB::startTransaction();
     $this->assert($depth === 1);
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 300, 'Abe');
     $depth = DB::startTransaction();
     $this->assert($depth === 2);
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 400, 'Abe');
     $depth = DB::rollback(true);
     $this->assert($depth === 0);
     $age = DB::queryFirstField("SELECT age FROM accounts WHERE username=%s", 'Abe');
     $this->assert($age == 200);
     DB::$nested_transactions = false;
 }
Ejemplo n.º 3
0
 function test_1_transactions()
 {
     DB::$nested_transactions = false;
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 600, 'Abe');
     $depth = DB::startTransaction();
     $this->assert($depth === 1);
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 700, 'Abe');
     $depth = DB::startTransaction();
     $this->assert($depth === 1);
     DB::query("UPDATE accounts SET age=%i WHERE username=%s", 800, 'Abe');
     $depth = DB::rollback();
     $this->assert($depth === 0);
     $age = DB::queryFirstField("SELECT age FROM accounts WHERE username=%s", 'Abe');
     $this->assert($age == 700);
     $depth = DB::rollback();
     $this->assert($depth === 0);
     $age = DB::queryFirstField("SELECT age FROM accounts WHERE username=%s", 'Abe');
     $this->assert($age == 700);
 }
Ejemplo n.º 4
0
 function __construct()
 {
     DB::startTransaction();
 }
 public function postPrefsAction()
 {
     $error = array();
     $mysql['campaign_type'] = @$_POST['campaign_type'];
     $mysql['click_filter'] = @$_POST['click_filter'];
     $mysql['user_mobile_breakdown_1'] = @$_POST['user_mobile_breakdown_1'];
     $mysql['user_mobile_breakdown_2'] = @$_POST['user_mobile_breakdown_2'];
     $mysql['user_mobile_breakdown_3'] = @$_POST['user_mobile_breakdown_3'];
     $mysql['user_mobile_breakdown_4'] = @$_POST['user_mobile_breakdown_4'];
     $mysql['traffic_source_id'] = @$_POST['traffic_source_id'];
     $mysql['breakdown'] = @$_POST['breakdown'];
     $mysql['campaign_id'] = @$_POST['campaign_id'];
     //predefined timelimit set, set the options
     if (@$_POST['time_predefined'] != '') {
         switch (@$_POST['time_predefined']) {
             case 'today':
             case 'yesterday':
             case 'last7':
             case 'last14':
             case 'last30':
             case 'thismonth':
             case 'lastmonth':
             case 'thisyear':
             case 'lastyear':
             case 'alltime':
                 $clean['time_predefined'] = @$_POST['time_predefined'];
                 break;
         }
         if (!isset($clean['time_predefined'])) {
             $error['time_predefined'] = '<div class="error">You choose an incorrect time user_preference</div>';
             echo $error['time_predefined'];
         }
     } else {
         $from = explode(' ', @$_POST['from']);
         $from = explode('/', $from[0]);
         $from_month = trim($from[0]);
         $from_day = trim($from[1]);
         $from_year = trim($from[2]);
         $to = explode(' ', @$_POST['to']);
         $to = explode('/', $to[0]);
         $to_month = trim($to[0]);
         $to_day = trim($to[1]);
         $to_year = trim($to[2]);
         //if from or to, validate, and if validated, set it accordingly
         if ($from != '' and checkdate($from_month, $from_day, $from_year) == false) {
             $error['date'] = '<div class="error">Wrong date format, you must use the following time format:   <strong>mm/dd/yyyy</strong></div>';
             echo $error['date'];
         } else {
             $clean['time_from'] = mktime(0, 0, 0, $from_month, $from_day, $from_year);
         }
         if ($to != '' and checkdate($to_month, $to_day, $to_year) == false) {
             $error['date'] = '<div class="error">Wrong date format, you must use the following time format:   <strong>mm/dd/yyyy</strong></div>';
             echo $error['date'];
         } else {
             $clean['time_to'] = mktime(23, 59, 59, $to_month, $to_day, $to_year);
         }
         if (!$error && $clean['time_to'] < $clean['time_from']) {
             $error['date'] = '<div class="error">The end date must be <strong>after</strong> the start date.</div>';
             echo $error['date'];
         }
     }
     if (!$error) {
         $mysql['time_predefined'] = getArrayVar($clean, 'time_predefined');
         $mysql['time_from'] = getArrayVar($clean, 'time_from');
         $mysql['time_to'] = getArrayVar($clean, 'time_to');
         $fields = getReportFieldsForPage($_POST['opt_setting']);
         DB::startTransaction();
         //Only add fields that should be on this page, so we don't overwrite other options
         foreach ($fields as $field => $val) {
             BTAuth::user()->setPref($field, $mysql[$field]);
         }
         DB::commit();
     }
 }
Ejemplo n.º 6
0
 public function duplicate($id)
 {
     DB::startTransaction();
     $query = "insert into " . $this->tableName() . " (name, user_id, traffic_source_id, rotate, cloaker_id, type)";
     $query .= "select concat(name,' copy') as name, user_id, traffic_source_id, rotate, cloaker_id, type from " . $this->tableName() . " ";
     $query .= "where campaign_id='" . DB::quote($id) . "'";
     if (!DB::query($query)) {
         DB::rollback();
         return false;
     }
     $new_id = DB::insertId();
     if (!$new_id) {
         DB::rollback();
         return false;
     }
     if (!CampaignOfferModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CampaignLPModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!CampaignOptionModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     if (!SpendingModel::model()->duplicate($id, $new_id)) {
         DB::rollback();
         return false;
     }
     DB::commit();
     return $new_id;
 }
 protected function editCampaign()
 {
     DB::startTransaction();
     if (!($campaign = CampaignModel::model()->getRowFromPk($_POST['campaign_id']))) {
         echo json_encode(array('message' => 'Could not save: invalid campaign ID'));
         DB::rollback();
         BTApp::end();
     }
     $campaign->name = $_POST['name'];
     $campaign->cloaker_id = $_POST['cloaker_id'];
     $campaign->slug = $_POST['slug'];
     $campaign->save();
     switch ($campaign->type) {
         case 1:
             foreach ($campaign->offers as $offer) {
                 if (!in_array($offer->id(), $_POST['campaign_lpoffer_id'])) {
                     $offer->delete();
                 }
             }
             for ($i = 0, $cnt = count($_POST['campaign_lpoffer_id']); $i < $cnt; $i++) {
                 $id = $_POST['campaign_lpoffer_id'][$i];
                 if (!$id) {
                     //new
                     $offer = OfferModel::model();
                     $offer->aff_network_id = $_POST['lpoffer_aff_network_id'][$i];
                     $offer->name = $_POST['lpoffer_name'][$i];
                     $offer->url = $_POST['lpoffer_url'][$i];
                     $offer->payout = $_POST['lpoffer_payout'][$i];
                     if (!$offer->save()) {
                         echo json_encode(array('message' => 'Could not add offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                     $campoffer = CampaignOfferModel::model();
                     $campoffer->campaign_id = $campaign->id();
                     $campoffer->position = 0;
                     $campoffer->weight = 0;
                     $campoffer->offer_id = $offer->id();
                     if (!$campoffer->save()) {
                         echo json_encode(array('message' => 'Could not add campaign offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                 } else {
                     //edit
                     $campoffer = CampaignOfferModel::model()->getRowFRomPk($id);
                     $offer = $campoffer->offer;
                     $offer->aff_network_id = $_POST['lpoffer_aff_network_id'][$i];
                     $offer->name = $_POST['lpoffer_name'][$i];
                     $offer->url = $_POST['lpoffer_url'][$i];
                     $offer->payout = $_POST['lpoffer_payout'][$i];
                     if (!$offer->save()) {
                         echo json_encode(array('message' => 'Could not save offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                 }
             }
             foreach ($campaign->landing_pages as $lp) {
                 if (!in_array($lp->id(), $_POST['campaign_lp_id'])) {
                     $lp->delete();
                 }
             }
             for ($i = 0, $cnt = count($_POST['campaign_lp_id']); $i < $cnt; $i++) {
                 $id = $_POST['campaign_lp_id'][$i];
                 if (!$id) {
                     //new
                     $lp = LandingPageModel::model();
                     $lp->name = $_POST['lp_name'][$i];
                     $lp->url = $_POST['lp_url'][$i];
                     if (!$lp->save()) {
                         echo json_encode(array('message' => 'Could not add LPs'));
                         DB::rollback();
                         BTApp::end();
                     }
                     $camp_lp = CampaignLPModel::model();
                     $camp_lp->campaign_id = $campaign->id();
                     $camp_lp->landing_page_id = $lp->id();
                     $camp_lp->weight = $_POST['lp_weight'][$i];
                     if (!$camp_lp->save()) {
                         echo json_encode(array('message' => 'Could not add campaign LPs'));
                         DB::rollback();
                         BTApp::end();
                     }
                 } else {
                     //edit
                     $camp_lp = CampaignLPModel::model()->getRowFromPk($id);
                     $camp_lp->weight = $_POST['lp_weight'][$i];
                     if (!$camp_lp->save()) {
                         echo json_encode(array('message' => 'Could not save campaign LPs'));
                         DB::rollback();
                         BTApp::end();
                     }
                     $lp = $camp_lp->landing_page;
                     $lp->name = $_POST['lp_name'][$i];
                     $lp->url = $_POST['lp_url'][$i];
                     if (!$lp->save()) {
                         echo json_encode(array('message' => 'Could not save LPs'));
                         DB::rollback();
                         BTApp::end();
                     }
                 }
             }
             break;
         case 2:
             foreach ($campaign->offers as $offer) {
                 if (!in_array($offer->id(), $_POST['campaign_offer_id'])) {
                     $offer->delete();
                 }
             }
             for ($i = 0, $cnt = count($_POST['campaign_offer_id']); $i < $cnt; $i++) {
                 $id = $_POST['campaign_offer_id'][$i];
                 if (!$id) {
                     //new
                     $offer = OfferModel::model();
                     $offer->aff_network_id = $_POST['offer_aff_network_id'][$i];
                     $offer->name = $_POST['offer_name'][$i];
                     $offer->url = $_POST['offer_url'][$i];
                     $offer->payout = $_POST['offer_payout'][$i];
                     if (!$offer->save()) {
                         echo json_encode(array('message' => 'Could not save offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                     $campoffer = CampaignOfferModel::model();
                     $campoffer->campaign_id = $campaign->id();
                     $campoffer->position = 0;
                     $campoffer->weight = $_POST['offer_weight'][$i];
                     $campoffer->offer_id = $offer->id();
                     if (!$campoffer->save()) {
                         echo json_encode(array('message' => 'Could not save offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                 } else {
                     //edit
                     $campoffer = CampaignOfferModel::model()->getRowFRomPk($id);
                     $campoffer->weight = $_POST['offer_weight'][$i];
                     if (!$campoffer->save()) {
                         echo json_encode(array('message' => 'Could not save offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                     $offer = $campoffer->offer;
                     $offer->name = $_POST['offer_name'][$i];
                     $offer->aff_network_id = $_POST['offer_aff_network_id'][$i];
                     $offer->url = $_POST['offer_url'][$i];
                     $offer->payout = $_POST['offer_payout'][$i];
                     if (!$offer->save()) {
                         echo json_encode(array('message' => 'Could not save offers'));
                         DB::rollback();
                         BTApp::end();
                     }
                 }
             }
             break;
     }
     foreach ($_POST['opt'] as $name => $val) {
         $opt = $campaign->options[$name];
         $opt->value = $val;
         if (!$opt->save()) {
             DB::rollback();
             echo json_encode(array('message' => 'Could not save options'));
             BTApp::end();
         }
     }
     foreach ($campaign->options as $option) {
         if (strpos($option->name, 'pass_') === 0) {
             $option->delete();
         }
     }
     for ($j = 0, $cnt = count($_POST['variable_name']); $j < $cnt; $j++) {
         $name = $_POST['variable_name'][$j];
         $name = 'pass_' . $name;
         if ($campaign->type == 1) {
             $pass_lp = $_POST['variable_lp'][$j];
             $pass_offer = $_POST['variable_offer'][$j];
             $val = json_encode(array('lp' => $pass_lp, 'offer' => $pass_offer));
         } else {
             $val = json_encode(array('offer' => '1'));
         }
         if (!$campaign->addOption($name, $val)) {
             DB::rollback();
             echo json_encode(array('message' => 'Could not save Variables Passthroughs'));
             BTApp::end();
         }
     }
     DB::commit();
     echo json_encode(array('message' => '2', 'campaign_id' => $campaign->id()));
 }