public function executeCronUpdateCoursesCount(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $this->params = $request->getGetParameters();
     $platform_short_name = $CFG->current_app->getShortName();
     $product_type = isset($this->params['type']) ? $this->params['type'] : "";
     // gets all available schools
     $eschool_array = array();
     $catalog_courses_count = array();
     foreach ($CFG->current_app->getMnetEschools() as $eschool) {
         //if (GcrEschoolTable::authorizeEschoolAccess($eschool, true)) {
         $eschool_array[$eschool->getFullName()] = $eschool;
         //}
     }
     ksort($eschool_array);
     // gets catalog-wise courses count
     foreach ($eschool_array as $eschool) {
         $catalog_courses_count[$eschool->getShortName()] = $this->getHTMLCoursesCount($eschool->getShortName());
     }
     // gets all products list
     $all_products = GcrProductsTable::getAllProducts($platform_short_name, $product_type);
     $all_products_details = array();
     foreach ($all_products as $product) {
         $all_products_details[$product->getShortName()]["id"] = $product->getId();
         $all_products_details[$product->getShortName()]["product_type_id"] = $product->getProductTypeId();
         $all_products_details[$product->getShortName()]["short_name"] = $product->getShortName();
         $all_products_details[$product->getShortName()]["institution_short_name"] = $product->getInstitutionShortName();
         $all_products_details[$product->getShortName()]["catalog_short_name"] = $product->getCatalogShortName();
         $all_products_details[$product->getShortName()]["platform_short_name"] = $product->getPlatformShortName();
         if ($product->getProductTypeId() == 2 || $product->getProductTypeId() == 3) {
             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $product->getCatalogShortName(), $product->getPlatformShortName());
             $ctlg_crses_count = isset($catalog_courses_count[$product->getCatalogShortName()]) ? $catalog_courses_count[$product->getCatalogShortName()] : 0;
             if ($is_exist == 0) {
                 $cron_obj = new GcrInstitutionCatalogCourses();
                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                 $cron_obj->setCatalogShortName($product->getCatalogShortName());
                 $cron_obj->setProductTypeId($product->getProductTypeId());
                 $cron_obj->setCoursesCount($ctlg_crses_count);
                 $cron_obj->save();
             } else {
                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $product->getCatalogShortName())->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
             }
         } else {
             if ($product->getProductTypeId() == 1) {
                 $institution_name = $product->getInstitutionShortName();
                 $mhr_institution_obj = $CFG->current_app->selectFromMhrTable('institution', 'name', $institution_name, true);
                 if ($mhr_institution_obj) {
                     $mhr_institution = new GcrMhrInstitution($mhr_institution_obj, $CFG->current_app);
                     $current_eschools = array();
                     $eschools = $mhr_institution->getEschools();
                     if ($eschools) {
                         foreach ($eschools as $eschool) {
                             $current_eschools[$eschool->getShortName()] = $eschool->getFullName();
                         }
                     }
                     asort($current_eschools);
                     foreach ($current_eschools as $current_eschool_key => $current_eschool_val) {
                         if (stripos(strtolower($current_eschool_val), "(*)") === false && stripos(strtolower($current_eschool_val), "(\$)") === false) {
                             $params = array();
                             $params["start_index"] = 0;
                             $params["mode"] = "Eschool";
                             $params["mode_id"] = $current_eschool_key;
                             $this->course_list = new GcrCourseList($params, $CFG->current_app);
                             $catalog_courses_count[$current_eschool_key] = $this->course_list->getCoursesCount();
                             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $current_eschool_key, $product->getPlatformShortName());
                             $ctlg_crses_count = isset($catalog_courses_count[$current_eschool_key]) ? $catalog_courses_count[$current_eschool_key] : 0;
                             if ($is_exist == 0) {
                                 $cron_obj = new GcrInstitutionCatalogCourses();
                                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                                 $cron_obj->setCatalogShortName($current_eschool_key);
                                 $cron_obj->setProductTypeId($product->getProductTypeId());
                                 $cron_obj->setCoursesCount($ctlg_crses_count);
                                 $cron_obj->save();
                             } else {
                                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $current_eschool_key)->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
                             }
                         }
                     }
                 }
             }
         }
     }
     /* 		print "<pre>";
     		print_r($catalog_courses_count);
     		//print_r($all_products_details);
     		print "</pre>"; */
     echo "<br>Completed<br>";
     exit;
 }