diff --git a/wrenchboard/src/shared_tool/site_crons.cc b/wrenchboard/src/shared_tool/site_crons.cc index 78bc269b..c4462116 100644 --- a/wrenchboard/src/shared_tool/site_crons.cc +++ b/wrenchboard/src/shared_tool/site_crons.cc @@ -39,6 +39,7 @@ long RefreshBlogs(CVars in, CVars &out); long RefreshPromoActivities(CVars in, CVars &out); long RegisterPromoPoint(CVars in); long RegisterPromoAction(CVars in); +long ReferEmailsCleanup(); /* CREATE TABLE cron_jobs ( @@ -270,6 +271,7 @@ long RefreshPromoActivities(CVars in, CVars &out){ } } + ReferEmailsCleanup(); // clean up account refer ret = PHP_API_OK; out["status"] = "OK"; @@ -280,6 +282,40 @@ long RefreshPromoActivities(CVars in, CVars &out){ return ret; } +long ReferEmailsCleanup(){ + + logfmt(logINFO, "ReferEmailsCleanup() *** **** **** ENTRY"); + char vname[30]; + long ret = PHP_API_BAD_PARAM; + out["total_record"] = "0"; + const PGresult *res, *resF; + + // check if pending + res = pgsql_query("SELECT id, email ,added, status FROM members_refer_friend WHERE status =1 AND added < now() + '-14 days' LIMIT 20"); + if (res != NULL && pgsql_num_rows(res) > 0) { + out["total_record"] = pgsql_num_rows(res); + + for (int i = 0, n = pgsql_num_rows(res); i < n; i++) { + mapf = pgsql_fetch_assoc(res, i); + if (f.empty()) continue; + CVars rec; + map_to_cvars(f, rec); + // check if on pending table + + const PGresult *res1 = pgsql_query("SELECT * FROM members WHERE email='%s'", rec["email"].c_str()); + if (res1 != NULL && pgsql_num_rows(res1) > 0) { + out["status"] = "Unable to add this email"; + pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s' AND id=%lu", rec["email"].c_str(), rec["id"].Long()); + } + else{ + pgsql_query("UPDATE members_refer_friend SET status = 0 WHERE status = 1 AND email = '%s' AND id=%lu", rec["email"].c_str(), rec["id"].Long()); + } + } + } + +return 0; +} + long RegisterPromoPoint(CVars in){ /* CREATE TABLE promo_points(