Example #1
0
 /**
  * CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES
  * Check all the services [domains, products] and create the orders for each customer only if the service has been set as renewable
  * @return void
  */
 public static function checkServices()
 {
     try {
         $i = 0;
         $customers = array();
         /* We have to start to get all the domains that them expiring date is today
         			 then we have to create a custom array sorted by customerID in order to
         			group services and domains of a specific customer.
         			*/
         // Get all the active domains that expire in 1 day
         $domains = Domains::getExpiringDomainsByDays(1, Statuses::id("active", "domains"));
         if ($domains) {
             Shineisp_Commons_Utilities::log("There are (" . count($domains) . ") new domains to renew");
             // Create the customer group list for the email summary
             foreach ($domains as $domain) {
                 if (is_numeric($domain['reseller'])) {
                     $invoice_dest = Customers::getAllInfo($domain['reseller']);
                     $customers[$domain['customer_id']]['id'] = $invoice_dest['customer_id'];
                     $customers[$domain['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                     $customers[$domain['customer_id']]['email'] = $invoice_dest['email'];
                     $customers[$domain['customer_id']]['language_id'] = $invoice_dest['language_id'];
                 } else {
                     $customers[$domain['customer_id']]['id'] = $domain['customer_id'];
                     $customers[$domain['customer_id']]['fullname'] = $domain['fullname'];
                     $customers[$domain['customer_id']]['email'] = $domain['email'];
                     $customers[$domain['customer_id']]['language_id'] = $domain['language_id'];
                 }
                 $customers[$domain['customer_id']]['products'][$i]['name'] = $domain['domain'];
                 $customers[$domain['customer_id']]['products'][$i]['type'] = "domain";
                 $customers[$domain['customer_id']]['products'][$i]['renew'] = $domain['renew'];
                 $customers[$domain['customer_id']]['products'][$i]['expiring_date'] = $domain['expiringdate'];
                 $customers[$domain['customer_id']]['products'][$i]['days'] = $domain['days'];
                 // Get the last old order item id
                 if (!empty($domain['oldorders'])) {
                     // find the domain
                     foreach ($domain['oldorders'] as $olditemorder) {
                         // Get all the information from the old order
                         $olditem = OrdersItems::getAllInfo($olditemorder['orderitem_id']);
                         // Check if the old order item refers to the domain selected
                         if (!empty($olditem['parameters']) && !empty($olditem['Orders']['OrdersItemsDomains'][0]['Domains']['tld_id'])) {
                             // Get the old configuration parameters
                             $params = json_decode($olditem['parameters'], true);
                             // 								Zend_Debug::dump($olditem);
                             // 								Zend_Debug::dump($params);
                             // 								Zend_Debug::dump($domain['domain']);
                             // Extract the domain name and match it with the domain selected
                             if (!empty($params['domain']) && $params['domain']['name'] == $domain['domain']) {
                                 $customers[$domain['customer_id']]['products'][$i]['oldorderitemid'] = $olditemorder['orderitem_id'];
                             }
                         }
                     }
                 }
                 Shineisp_Commons_Utilities::log("- " . $domain['domain']);
                 $i++;
             }
         }
         /*
          * Now we have to get the services expired and we have to sum the previous $customers array with these
          * new information.
          */
         // Get all the services active that expire the day after
         $services = OrdersItems::getExpiringServicesByDays(1, Statuses::id("complete", "orders"));
         if ($services) {
             Shineisp_Commons_Utilities::log("There are (" . count($services) . ") new services to renew");
             // Create the customer group list for the email summary
             foreach ($services as $service) {
                 if (is_numeric($service['reseller'])) {
                     $invoice_dest = Customers::getAllInfo($service['reseller']);
                     $customers[$service['customer_id']]['id'] = $invoice_dest['customer_id'];
                     $customers[$service['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                     $customers[$service['customer_id']]['email'] = $invoice_dest['email'];
                     $customers[$service['customer_id']]['password'] = $invoice_dest['password'];
                     $customers[$service['customer_id']]['language_id'] = $invoice_dest['language_id'];
                 } else {
                     $customers[$service['customer_id']]['id'] = $service['id'];
                     $customers[$service['customer_id']]['fullname'] = $service['fullname'];
                     $customers[$service['customer_id']]['email'] = $service['email'];
                     $customers[$service['customer_id']]['password'] = $service['password'];
                     $customers[$service['customer_id']]['language_id'] = $service['language_id'];
                 }
                 $customers[$service['customer_id']]['products'][$i]['name'] = $service['product'];
                 $customers[$service['customer_id']]['products'][$i]['type'] = "service";
                 $customers[$service['customer_id']]['products'][$i]['renew'] = $service['renew'];
                 $customers[$service['customer_id']]['products'][$i]['expiring_date'] = $service['expiringdate'];
                 $customers[$service['customer_id']]['products'][$i]['days'] = $service['days'];
                 $customers[$service['customer_id']]['products'][$i]['oldorderitemid'] = $service['detail_id'];
                 Shineisp_Commons_Utilities::log("- " . $service['product']);
                 $i++;
             }
         }
         // Create the email messages for the customers
         if (count($customers) > 0) {
             foreach ($customers as $customer) {
                 $items = "";
                 // **** CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES ***
                 // ============================================================
                 // Renew all the services and domain where the customer has choosen the autorenew of the service.
                 $orderID = Orders::renewOrder($customer['id'], $customer['products']);
                 if (is_numeric($orderID)) {
                     $link = Fastlinks::findlinks($orderID, $customer['id'], 'orders');
                     // Create the fast link to include in the email
                     if (!empty($link[0]['code'])) {
                         $url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code'];
                     } else {
                         $url = "http://" . $_SERVER['HTTP_HOST'];
                     }
                     Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_renew', array('fullname' => $customer['fullname'], ':shineisp:' => $customer, 'url' => $url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify'));
                 }
             }
         }
         /*
          * Now we have to set as expired all the domains records that the date is the date of the expiring of the domain
          * // Expired
          */
         $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('expired', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', 0)->addWhere('DATEDIFF(d.expiring_date, CURRENT_DATE) >= ?', 0);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as closed all the domains records that the date is older of -2 days
          * // Closed
          */
         $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('suspended', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', -2);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as expired all the services records
          * // Expired
          */
         $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('expired', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', 0);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         /*
          * Now we have to set as deleted all the services records
          * // Deleted
          */
         $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('deleted', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', -2);
         $dq->execute(null, Doctrine::HYDRATE_ARRAY);
         Shineisp_Commons_Utilities::sendEmailTemplate(null, 'cron', array('cronjob' => 'Check Services'), null, null, null, null, null, Settings::findbyParam('cron_notify'));
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::logs($e->getMessage(), "cron.log");
         return false;
     }
     return true;
 }