function hooks_call()
 {
     $src_obj = new SourceRepositories();
     $source_repo_table = TABLE_PREFIX . "source_repositories";
     $res = $src_obj->findBySQL("select * from {$source_repo_table} where name = '" . trim($_GET["repo_name"]) . "'");
     if ($res) {
         $repo_array = $res->getRowAt(0);
         GitoliteAdmin::update_remote_repo($repo_array->getId(), TRUE);
     }
     die;
 }
 /**
  * Prepare controller
  */
 function __before()
 {
     parent::__before();
     $repository_id = $this->request->getId('source_repository_id');
     if ($repository_id) {
         $this->active_repository = SourceRepositories::findById($repository_id);
         if ($this->active_repository instanceof SourceRepository && !$this->active_repository instanceof GitRepository) {
             $this->httpError(HTTP_ERR_CONFLICT);
         }
     }
     if (!$this->active_repository instanceof GitRepository) {
         $this->active_repository = new GitRepository();
     }
     $this->smarty->assign('active_repository', $this->active_repository);
 }
 /**
  * Update remote repository after adding in database
  *
  * @param integer $repo_id
  *
  * @return string result
  */
 function update_remote_repo($repo_id = 0, $call_hooks = false)
 {
     require_once ANGIE_PATH . '/classes/xml/xml2array.php';
     $source_obj = new SourceRepositories();
     $source_repositories = $source_obj->findById($repo_id);
     self::update_repo_code($repo_id);
     if ($source_repositories) {
         $results = "";
         foreach ($source_repositories as $source_repository) {
             $project_source_repositories = ProjectSourceRepositories::findByParent($source_repositories);
             if (($error = $source_repositories->loadEngine()) !== true) {
                 return $error;
             }
             // if
             if (!($repository_engine = $source_repositories->getEngine())) {
                 return lang('Failed to load repository engine class');
             }
             // if
             if (is_error($repository_engine->error)) {
                 $results .= lang('Error connecting to repository ') . ' ' . $source_repositories->getName() . ': ' . $repository_engine->error->getMessage();
                 continue;
             }
             //if
             $branches = $source_repositories->hasBranches() ? $repository_engine->getBranches() : array('');
             foreach ($branches as $branch) {
                 $repository_engine->active_branch = $branch;
                 $last_commit = $source_repositories->getLastCommit($branch);
                 $latest_revision = $last_commit instanceof SourceCommit ? $last_commit->getRevisionNumber() : $repository_engine->getZeroRevision() - 1;
                 $head_revision = $repository_engine->getHeadRevision();
                 if (!$head_revision) {
                     $results .= lang('Connection to') . ' ' . $source_repositories->getName() . ' ' . lang('failed') . '. ' . lang('Please contact repository server administrator');
                     continue;
                 }
                 //if
                 if (!is_null($repository_engine->error) || $latest_revision == $head_revision) {
                     continue;
                 }
                 //if
                 $revision_from = $latest_revision + 1;
                 $revision_to = $revision_from + $repository_engine->getModuleLogsPerRequest() - 1;
                 if ($revision_to >= $head_revision) {
                     $revision_to = $head_revision;
                 }
                 //if
                 $logs = $repository_engine->getLogs($revision_from, $revision_to);
                 if (!is_null($repository_engine->error)) {
                     continue;
                 }
                 //if
                 //die();
                 /* commits.append({'id': r['id'],
                 	  'author': {'name': r['name'], 'email': r['email']},
                 	  'url': url,
                 	  'message': r['message'],
                 	  'timestamp': r['date']
                 	  }) */
                 $hooks_table_name = TABLE_PREFIX . "rt_web_hooks";
                 $get_repo_hooks = DB::execute("SELECT * from {$hooks_table_name} where repo_fk = '" . $repo_id . "'");
                 if ($get_repo_hooks) {
                     $array_pay_load = array();
                     // get last commit
                     $before = $source_repositories->getLastCommit($branch, 1);
                     if (isset($before) && $before != null) {
                         $array_pay_load["before"] = $before->getName();
                     } else {
                         $array_pay_load["before"] = "";
                     }
                 }
                 $source_repositories->update($logs['data'], $branch);
                 //print_r($logs['data']);
                 // call hooks added on repositories
                 if ($get_repo_hooks) {
                     $array_commits = array();
                     if (is_foreachable($logs['data'])) {
                         $array_pay_load["repository"] = array("url" => $source_repositories->getViewUrl(), "name" => $source_repositories->getName(), "description" => "", "owner" => array("email" => $source_repositories->getCreatedByEmail(), "name" => $source_repositories->getCreatedBy()->getName()));
                         $k = 0;
                         foreach ($logs['data'] as $data) {
                             $array_added = array();
                             $array_modified = array();
                             $array_deleted = array();
                             $array_commits = array();
                             $array_commits["id"] = urlencode($data['commit']['name']);
                             $array_commits["url"] = "";
                             $array_commits["author"] = array("email" => $data['commit']['authored_by_email'], "name" => $data['commit']['authored_by_name']);
                             $array_commits["message"] = urlencode($data['commit']['message_body']);
                             $array_commits["message"] = urlencode($data['commit']['message_body']);
                             $array_commits["message_title"] = urlencode($data['commit']['message_title']);
                             $array_commits["timestamp"] = urlencode($data['commit']['commited_on']);
                             $paths_array = unserialize($data["paths"]);
                             if (is_foreachable($paths_array)) {
                                 foreach ($paths_array as $key_paths => $value_paths) {
                                     if ($value_paths["action"] == "A") {
                                         $array_added[] = $value_paths["path"];
                                     } elseif ($value_paths["action"] == "M") {
                                         $array_modified[] = $value_paths["path"];
                                     } elseif ($value_paths["action"] == "D") {
                                         $array_deleted[] = $value_paths["path"];
                                     }
                                 }
                             }
                             $array_commits["added"] = $array_added;
                             $array_commits["removed"] = $array_deleted;
                             $array_commits["modified"] = $array_modified;
                             $last_commit_payload = $data['commit']['name'];
                             // keep assigning commits , as we need last commit id
                             $array_pay_load["commits"][] = $array_commits;
                             //print_r($data);
                             //print_r(unserialize($data["paths"]));
                             $k++;
                         }
                         $array_pay_load["after"] = $last_commit_payload;
                         $array_pay_load["ref"] = "refs/heads/" . $branch;
                     }
                     //foreach($array_commits as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
                     $fields_string = json_encode($array_pay_load);
                     if ($get_repo_hooks) {
                         $url_array = $get_repo_hooks[0];
                         $url_array = @unserialize($url_array["webhook_urls"]);
                         if (is_foreachable($url_array)) {
                             foreach ($url_array as $key_url => $value_url) {
                                 $url = $value_url;
                                 rtrim($fields_string, '&');
                                 //open connection
                                 $ch = curl_init();
                                 //set the url, number of POST vars, POST data
                                 curl_setopt($ch, CURLOPT_URL, $url);
                                 curl_setopt($ch, CURLOPT_POST, count($array_pay_load));
                                 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
                                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($fields_string)));
                                 //execute post
                                 $curl_result = curl_exec($ch);
                                 $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                 curl_close($ch);
                             }
                         }
                     }
                 }
                 // call hooks added on repositories ends here
                 // deploy on FTP as per details added under repositories
                 // deploy on FTP as per details added under repositories ends here
                 $total_commits = $logs['total'] - $logs['skipped_commits'];
                 $branch_string = $branch ? ' ' . lang('Branch') . ': ' . $branch : '';
                 $results .= $source_repositories->getName() . $branch_string . ' (' . $total_commits . ' ' . lang('new commits') . '); \\n';
                 $repo_table_name = TABLE_PREFIX . "rt_gitolite_repomaster";
                 $res_repo_details = DB::execute("SELECT * from {$repo_table_name} where repo_fk = '" . $source_repositories->getId() . "'");
                 if ($res_repo_details) {
                     $repo_details = $res_repo_details[0];
                     $send_notifi = $repo_details["disable_notifications"];
                 } else {
                     $send_notifi = "no";
                 }
                 if ($send_notifi == "no") {
                     foreach ($project_source_repositories as $project_source_repository) {
                         if ($total_commits <= MAX_UPDATED_COMMITS_TO_SEND_DETAILED_NOTIFICATIONS) {
                             $project_source_repository->detailed_notifications = true;
                         }
                         //if
                         $project_source_repository->last_update_commits_count = $total_commits;
                         $project_source_repository->source_repository = $source_repositories;
                         ProjectSourceRepositories::sendCommitNotificationsToSubscribers($project_source_repository);
                         $project_source_repository->createActivityLog();
                     }
                     //foreach
                 }
                 //} //if
                 //} //if
             }
             // foreach
         }
         if (empty($results)) {
             //self::update_repo_code($repo_id);
         } else {
             lang('Updated repositories: \\n') . $results;
         }
     } else {
         // self::update_repo_code($repo_id);
         echo lang('No repositories for update');
     }
 }
 /**
  * Delete repository from system
  * @return string message
  */
 function delete_repo()
 {
     $repoid = array_var($_GET, 'repoid');
     if ($repoid != "") {
         $this->active_repository = SourceRepositories::findById($repoid);
         $this->active_repository->delete();
         $repo_table_name = TABLE_PREFIX . 'rt_gitolite_repomaster';
         $repo_access_table_name = TABLE_PREFIX . 'rt_gitolite_access_master';
         DB::execute("DELETE repo_acc,repo_tb FROM {$repo_table_name} repo_tb\n                        JOIN {$repo_access_table_name} repo_acc ON repo_acc.repo_id = repo_tb.repo_id\n                        WHERE repo_tb.repo_fk = '" . $this->active_repository->getId() . "'");
         die("ok");
     } else {
         die("Problem occured while deleting repository");
     }
 }