Index: trunk/admin/install/upgrades/inportal_upgrade_v1.1.1.sql =================================================================== diff -u -N -r2184 -r2199 --- trunk/admin/install/upgrades/inportal_upgrade_v1.1.1.sql (.../inportal_upgrade_v1.1.1.sql) (revision 2184) +++ trunk/admin/install/upgrades/inportal_upgrade_v1.1.1.sql (.../inportal_upgrade_v1.1.1.sql) (revision 2199) @@ -26,6 +26,11 @@ INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('CATEGORY.MODIFY', -1, 0, 0, 0); INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('FAVORITES', -1, 0, 0, 0); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRED', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expired', '0'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRED', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expired', '1'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRATION_NOTICE', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expiration_notice', '0'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRATION_NOTICE', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expiration_notice', '1'); + ALTER TABLE UserGroup ADD MembershipExpires INT UNSIGNED DEFAULT NULL AFTER GroupId; UPDATE Modules SET Version = '1.1.1' WHERE Name = 'In-Portal'; \ No newline at end of file Index: trunk/core/kernel/application.php =================================================================== diff -u -N -r2112 -r2199 --- trunk/core/kernel/application.php (.../application.php) (revision 2112) +++ trunk/core/kernel/application.php (.../application.php) (revision 2199) @@ -366,9 +366,13 @@ } //eval("?".">".$this->HTML); + echo $this->HTML; $this->Phrases->UpdateCache(); + flush(); + $this->RunScheduledEvents(); + $session =& $this->recallObject('Session'); $session->SaveData(); //$this->SaveBlocksCache(); @@ -1320,6 +1324,11 @@ return 0; } + function RunScheduledEvents() + { + + } + } ?> \ No newline at end of file Index: trunk/kernel/units/users/users_event_handler.php =================================================================== diff -u -N -r2186 -r2199 --- trunk/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 2186) +++ trunk/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 2199) @@ -670,27 +670,31 @@ { foreach($user_ids as $id) { - + $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP_EXPIRED', $id); + $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP_EXPIRED'); } } $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); $this->Conn->Query($sql); - $pre_expiration = mktime() - $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; - $sql = 'SELECT PortalUserId FROM '.TABLE_PREFIX.'UserGroup + $pre_expiration = mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; + $sql = 'SELECT PortalUserId, GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.$pre_expiration.' AND ExpirationReminderSent = 0'; - $user_ids = $this->Conn->GetCol($sql); - if(is_array($user_ids) && count($user_ids) > 0) + $res = $this->Conn->Query($sql); + if(is_array($res) && count($res) > 0) { - foreach($user_ids as $id) + $conditions = Array(); + foreach($res as $record) { - + $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP_EXPIRATION_NOTICE', $record['PortalUserId']); + $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP_EXPIRATION_NOTICE'); + $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')'; } $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup SET ExpirationReminderSent = 1 - WHERE PortalUserId IN ('.implode($user_ids).')'; + WHERE '.implode(' OR ', $conditions); $this->Conn->Query($sql); } } Index: trunk/admin/install/upgrades/readme_1_1_1.txt =================================================================== diff -u -N -r2195 -r2199 --- trunk/admin/install/upgrades/readme_1_1_1.txt (.../readme_1_1_1.txt) (revision 2195) +++ trunk/admin/install/upgrades/readme_1_1_1.txt (.../readme_1_1_1.txt) (revision 2199) @@ -6,4 +6,5 @@ 0008131 - Admin -> Groups -> Group Edit (with no users in it) -> Users List -> SQL Error. Fixed 0008058 - Parsing 2 templates instead of 1 when pressing Logout from Store 0008188 - Suggest a site resulted incorrect object assignment. Fixed. -0008217 - During install set admin email to portal@domain, where "domain" is the one from license \ No newline at end of file +0008210 - Added maintain script functionality, added corresponding events +0008217 - During install set admin email to portal@domain, where "domain" is the one from license Index: trunk/core/units/users/users_event_handler.php =================================================================== diff -u -N -r2186 -r2199 --- trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 2186) +++ trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 2199) @@ -670,27 +670,31 @@ { foreach($user_ids as $id) { - + $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP_EXPIRED', $id); + $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP_EXPIRED'); } } $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); $this->Conn->Query($sql); - $pre_expiration = mktime() - $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; - $sql = 'SELECT PortalUserId FROM '.TABLE_PREFIX.'UserGroup + $pre_expiration = mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; + $sql = 'SELECT PortalUserId, GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.$pre_expiration.' AND ExpirationReminderSent = 0'; - $user_ids = $this->Conn->GetCol($sql); - if(is_array($user_ids) && count($user_ids) > 0) + $res = $this->Conn->Query($sql); + if(is_array($res) && count($res) > 0) { - foreach($user_ids as $id) + $conditions = Array(); + foreach($res as $record) { - + $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP_EXPIRATION_NOTICE', $record['PortalUserId']); + $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP_EXPIRATION_NOTICE'); + $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')'; } $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup SET ExpirationReminderSent = 1 - WHERE PortalUserId IN ('.implode($user_ids).')'; + WHERE '.implode(' OR ', $conditions); $this->Conn->Query($sql); } } Index: trunk/core/units/general/my_application.php =================================================================== diff -u -N -r1662 -r2199 --- trunk/core/units/general/my_application.php (.../my_application.php) (revision 1662) +++ trunk/core/units/general/my_application.php (.../my_application.php) (revision 2199) @@ -41,6 +41,45 @@ $this->SetVar('u_id', $user_id); $this->StoreVar('user_id', $user_id); } + + function RunScheduledEvents() + { + $events = Array('ls:OnCheckExpiredPaidListings', 'u:OnCheckExpiredMembership'); + $run_interval = 3600 * 24; // in seconds + + if(rand(0, 100) < 90) + { + return; + } + + $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "LastMaintainRun"'; + $last_maintain = $this->DB->GetOne($sql); + if($last_maintain && $last_maintain > mktime() - $run_interval) + { + return; + } + elseif($last_maintain) + { + $sql = 'UPDATE '.TABLE_PREFIX.'Cache SET Data = "'.mktime().'" + WHERE VarName = "LastMaintainRun"'; + } + else + { + $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) + VALUES ("LastMaintainRun", "'.mktime().'", "'.mktime().'")'; + } + $this->DB->Query($sql); + + foreach($events as $scheduled_event) + { + list($prefix, $event_name) = explode(':', $scheduled_event); + $event =& new kEvent(); + $event->Init($prefix); + $event->Name = $event_name; + $this->HandleEvent($event); + unset($event); + } + } } ?> \ No newline at end of file Index: trunk/kernel/units/general/my_application.php =================================================================== diff -u -N -r1662 -r2199 --- trunk/kernel/units/general/my_application.php (.../my_application.php) (revision 1662) +++ trunk/kernel/units/general/my_application.php (.../my_application.php) (revision 2199) @@ -41,6 +41,45 @@ $this->SetVar('u_id', $user_id); $this->StoreVar('user_id', $user_id); } + + function RunScheduledEvents() + { + $events = Array('ls:OnCheckExpiredPaidListings', 'u:OnCheckExpiredMembership'); + $run_interval = 3600 * 24; // in seconds + + if(rand(0, 100) < 90) + { + return; + } + + $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "LastMaintainRun"'; + $last_maintain = $this->DB->GetOne($sql); + if($last_maintain && $last_maintain > mktime() - $run_interval) + { + return; + } + elseif($last_maintain) + { + $sql = 'UPDATE '.TABLE_PREFIX.'Cache SET Data = "'.mktime().'" + WHERE VarName = "LastMaintainRun"'; + } + else + { + $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) + VALUES ("LastMaintainRun", "'.mktime().'", "'.mktime().'")'; + } + $this->DB->Query($sql); + + foreach($events as $scheduled_event) + { + list($prefix, $event_name) = explode(':', $scheduled_event); + $event =& new kEvent(); + $event->Init($prefix); + $event->Name = $event_name; + $this->HandleEvent($event); + unset($event); + } + } } ?> \ No newline at end of file Index: trunk/admin/install/inportal_data.sql =================================================================== diff -u -N -r2184 -r2199 --- trunk/admin/install/inportal_data.sql (.../inportal_data.sql) (revision 2184) +++ trunk/admin/install/inportal_data.sql (.../inportal_data.sql) (revision 2199) @@ -191,6 +191,10 @@ INSERT INTO Events VALUES (64, 'USER.SUGGEST', '1', '0', 'In-Portal:Users', 'la_event_user.suggest', '0'); INSERT INTO Events VALUES (65, 'USER.SUGGEST', '2', '0', 'In-Portal:Users', 'la_event_user.suggest', '1'); INSERT INTO Events VALUES (67, 'USER.PSWDC', '1', '0', 'In-Portal:Users', 'la_event_user.pswd_confirm', '0'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRED', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expired', '0'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRED', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expired', '1'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRATION_NOTICE', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expiration_notice', '0'); +INSERT INTO Events VALUES ('', 'USER.MEMBERSHIP_EXPIRATION_NOTICE', '1', '0', 'In-Portal:Users', 'la_event_user.membership_expiration_notice', '1'); INSERT INTO IdGenerator VALUES ('100');