promo to new group (Where is my screw up)

Started by MrRep, September 30, 2011, 04:16:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CodeMonkey

Replace,

//== Updated promote elite users
  $limit = 25*1024*1024*1024;
$minratio = 2.01;
$maxdt = (time() - 86400*56);
    $res = sql_query("SELECT id, uploaded, downloaded, invites, modcomment FROM users WHERE class = ".UC_POWER_USER." AND uploaded >= $limit AND uploaded / downloaded >= $minratio AND enabled='yes' AND added < $maxdt") or sqlerr(__FILE__, __LINE__);
    $msgs_buffer = $users_buffer = array();
    if (mysql_num_rows($res) > 0) {
        $subject ="Auto Promotion";
        $msg = "Congratulations, you have been Auto-Promoted to [b]PA elite User[/b]. :)\n You get one extra invite.\n";
        while ($arr = mysql_fetch_assoc($res)) {
            $ratio = number_format($arr['uploaded'] / $arr['downloaded'], 3);
            $modcomment = $arr['modcomment'];
            $modcomment =  get_date( time(), 'DATE', 1 ) . " - Promoted to Power User by System (UL=" . mksize($arr['uploaded']) . ", DL=" . mksize($arr['downloaded']) . ", R=" . $ratio . ").\n". $modcomment;
            $modcom =  sqlesc($modcomment);
            $msgs_buffer[] = '(0,' . $arr['id'] . ', '. TIME_NOW .', ' . sqlesc($msg) . ', ' . sqlesc($subject) . ')';
            $users_buffer[] = '(' . $arr['id'] . ', 1, 1, ' . $modcom . ')';
            $update['invites'] = ($arr['invites'] + 1);
            $mc1->begin_transaction('user'.$arr['id']);
            $mc1->update_row(false, array('class' => 1, 'invites' => $update['invites'], 'modcomment' => $modcomment));
            $mc1->commit_transaction(900);
            $mc1->begin_transaction('MyUser_'.$arr['id']);
            $mc1->update_row(false, array('class' => 2, 'invites' => $update['invites']));
            $mc1->commit_transaction(900);
        }
        $count = count($users_buffer);
        if ($count > 0){
            sql_query("INSERT INTO messages (sender,receiver,added,msg,subject) VALUES " . implode(', ', $msgs_buffer)) or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO users (id, class, invites, modcomment) VALUES " . implode(', ', $users_buffer) . " ON DUPLICATE key UPDATE class=values(class), invites = invites+values(invites), modcomment=concat(values(modcomment),modcomment)") or sqlerr(__FILE__, __LINE__);
            write_log("Cleanup: Promoted ".$count." member(s) from PA Power to PA Elite");
        }
        unset ($users_buffer, $msgs_buffer, $update, $count);
        status_change($arr['id']); //== For Retros announcement mod
    }


With
//== Updated promote Elite Users
  $limit = 25*1024*1024*1024;
$minratio = 2.01;
$maxdt = (time() - 86400*28);
    $res = sql_query("SELECT id, uploaded, downloaded FROM users WHERE class = 1 AND uploaded >= $limit AND uploaded / downloaded >= $minratio AND enabled='yes' AND added < $maxdt") or sqlerr(__FILE__, __LINE__);
    $msgs_buffer = $users_buffer = array();
    if (mysql_num_rows($res) > 0) {
        $subject ="Auto Promotion";
        $msg = "Congratulations, you have been Auto-Promoted to [b]Elite User[/b]. :)\n You get one extra invite.\n";
        while ($arr = mysql_fetch_assoc($res)) {
            $ratio = number_format($arr['uploaded'] / $arr['downloaded'], 3);
            $modcomment = sqlesc(get_date( time(), 'DATE', 1 ) . " - Promoted to Power User by System (UL=" . mksize($arr['uploaded']) . ", DL=" . mksize($arr['downloaded']) . ", R=" . $ratio . ") \n");
            $msgs_buffer[] = '(0,' . $arr['id'] . ', '.time().', ' . sqlesc($msg) . ', ' . sqlesc($subject) . ')';
            $users_buffer[] = '(' . $arr['id'] . ', 1, 1, ' . $modcomment . ')';
        }
        if (sizeof($msgs_buffer) > 0) {
            sql_query("INSERT INTO messages (sender,receiver,added,msg,subject) VALUES " . implode(', ', $msgs_buffer)) or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO users (id, class, invites, modcomment) VALUES " . implode(', ', $users_buffer) . " ON DUPLICATE key UPDATE class=2, invites = invites+values(invites), modcomment=concat(values(modcomment),modcomment)") or sqlerr(__FILE__, __LINE__);
            $count = mysql_affected_rows();
            write_log("Cleanup: Promoted " . $count / 2 . " member(s) from User to Elite User");
        }
        unset ($users_buffer);
        unset ($msgs_buffer);
        status_change($arr['id']); //== For Retros announcement mod
    }


Hope this helps :)
Do NOT PM me directly post in the forums so other users can benefit also :) If you like my posts 1+rep me :)

cherwonk

Hope you changed the modcomment
$modcomment =  get_date( time(), 'DATE', 1 ) . " - Promoted to Power User by System (UL=" . mksize($arr['uploaded']) . ", DL=" . mksize($arr['downloaded']) . ", R=" . $ratio . ").\n". $modcomment;

Had this on the site I coded for when it was up, But was Extreme User class and Elite VIP . Only had the auto promote for ExtUser though.
Glad you got it fixed..

MrRep

#1
ok what have i done wrong here, i have an elite class after power user, that i want members to auto promote to, but for some reason, it's not moving them to the new group and seems to loop around. It does send the pm, so any help on my screw up would be grate full.

Thanks


  //== Updated promote elite users
  $limit = 25*1024*1024*1024;
$minratio = 2.01;
$maxdt = (time() - 86400*56);
    $res = sql_query("SELECT id, uploaded, downloaded, invites, modcomment FROM users WHERE class = ".UC_POWER_USER." AND uploaded >= $limit AND uploaded / downloaded >= $minratio AND enabled='yes' AND added < $maxdt") or sqlerr(__FILE__, __LINE__);
    $msgs_buffer = $users_buffer = array();
    if (mysql_num_rows($res) > 0) {
        $subject ="Auto Promotion";
        $msg = "Congratulations, you have been Auto-Promoted to [b]PA elite User[/b]. :)\n You get one extra invite.\n";
        while ($arr = mysql_fetch_assoc($res)) {
            $ratio = number_format($arr['uploaded'] / $arr['downloaded'], 3);
            $modcomment = $arr['modcomment'];
            $modcomment =  get_date( time(), 'DATE', 1 ) . " - Promoted to Power User by System (UL=" . mksize($arr['uploaded']) . ", DL=" . mksize($arr['downloaded']) . ", R=" . $ratio . ").\n". $modcomment;
            $modcom =  sqlesc($modcomment);
            $msgs_buffer[] = '(0,' . $arr['id'] . ', '. TIME_NOW .', ' . sqlesc($msg) . ', ' . sqlesc($subject) . ')';
            $users_buffer[] = '(' . $arr['id'] . ', 1, 1, ' . $modcom . ')';
            $update['invites'] = ($arr['invites'] + 1);
            $mc1->begin_transaction('user'.$arr['id']);
            $mc1->update_row(false, array('class' => 1, 'invites' => $update['invites'], 'modcomment' => $modcomment));
            $mc1->commit_transaction(900);
            $mc1->begin_transaction('MyUser_'.$arr['id']);
            $mc1->update_row(false, array('class' => 2, 'invites' => $update['invites']));
            $mc1->commit_transaction(900);
        }
        $count = count($users_buffer);
        if ($count > 0){
            sql_query("INSERT INTO messages (sender,receiver,added,msg,subject) VALUES " . implode(', ', $msgs_buffer)) or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO users (id, class, invites, modcomment) VALUES " . implode(', ', $users_buffer) . " ON DUPLICATE key UPDATE class=values(class), invites = invites+values(invites), modcomment=concat(values(modcomment),modcomment)") or sqlerr(__FILE__, __LINE__);
            write_log("Cleanup: Promoted ".$count." member(s) from PA Power to PA Elite");
        }
        unset ($users_buffer, $msgs_buffer, $update, $count);
        status_change($arr['id']); //== For Retros announcement mod
    }
    //== Updated demote elite users
    $minratio = 1.85;
    $res = sql_query("SELECT id, uploaded, downloaded, modcomment FROM users WHERE class = ".UC_PAELITE." AND uploaded / downloaded < $minratio") or sqlerr(__FILE__, __LINE__);
    $subject ="Auto Demotion";
    $msgs_buffer = $users_buffer = array();
    if (mysql_num_rows($res) > 0) {
        $msg = "You have been auto-demoted from [b]PA Elite[/b] to [b]PA Power[/b] because your share ratio has dropped below  $minratio.\n";
        while ($arr = mysql_fetch_assoc($res)) {
            $ratio = number_format($arr['uploaded'] / $arr['downloaded'], 3);
            $modcomment = $arr['modcomment'];
            $modcomment =  get_date( time(), 'DATE', 1 ) . " - Demoted To PA Power by System (UL=" . mksize($arr['uploaded']) . ", DL=" . mksize($arr['downloaded']) . ", R=" . $ratio . ").\n". $modcomment;
            $modcom =  sqlesc($modcomment);
            $msgs_buffer[] = '(0,' . $arr['id'] . ', '. TIME_NOW .', ' . sqlesc($msg) . ', ' . sqlesc($subject) . ')';
            $users_buffer[] = '(' . $arr['id'] . ', 0, ' . $modcom . ')';
            $mc1->begin_transaction('user'.$arr['id']);
            $mc1->update_row(false, array('class' => 0, 'modcomment' => $modcomment));
            $mc1->commit_transaction(900);
            $mc1->begin_transaction('MYuser_'.$arr['id']);
            $mc1->update_row(false, array('class' => 1));
            $mc1->commit_transaction(900);
        }
        $count = count($users_buffer);
        if ($count > 0){
            sql_query("INSERT INTO messages (sender,receiver,added,msg,subject) VALUES " . implode(', ', $msgs_buffer)) or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO users (id, class, modcomment) VALUES " . implode(', ', $users_buffer) . " ON DUPLICATE key UPDATE class=values(class),modcomment=concat(values(modcomment),modcomment)") or sqlerr(__FILE__, __LINE__);
            write_log("Cleanup: Demoted ".$count." member(s) from Power User to User");
            status_change($arr['id']);
        }
        unset ($users_buffer, $msgs_buffer, $count);
        status_change($arr['id']); //== For Retros announcement mod
    }
  //==End


edit, ok fixed it :)