31 const NAME =
"upload_vcs";
32 const GETURL_PARAM =
'geturl';
34 public function __construct()
36 parent::__construct(self::NAME, array(
37 self::TITLE => _(
"Upload from Version Control System"),
38 self::MENU_LIST =>
"Upload::From Version Control System",
39 self::DEPENDENCIES => array(
"agent_unpack",
"showjobs"),
50 $vars[
'vcstypeField'] =
'vcstype';
51 $vars[
'usernameField'] =
'username';
52 $vars[
'passwdField'] =
'passwd';
53 $vars[
'geturlField'] = self::GETURL_PARAM;
54 $vars[
'branchField'] =
'branch';
55 $vars[
'nameField'] =
'name';
56 $this->renderer->clearTemplateCache();
57 $this->renderer->clearCacheFiles();
58 return $this->
render(
"upload_vcs.html.twig", $this->mergeWithDefault($vars));
70 $folderId = intval($request->get(self::FOLDER_PARAMETER_NAME));
71 $description = stripslashes($request->get(self::DESCRIPTION_INPUT_NAME));
72 $description = $this->basicShEscaping($description);
74 $getUrlThatMightIncludeSpaces =
trim($request->get(self::GETURL_PARAM));
75 $getUrl = str_replace(
" ",
"%20", $getUrlThatMightIncludeSpaces);
78 return array(
false, _(
"Empty URL") . $getUrl, $description);
80 if (preg_match(
"@^((http)|(https))://([[:alnum:]]+)@i", $getUrl) != 1) {
81 return array(
false, _(
"Invalid URL") . $getUrl, $description);
83 $getUrl = $this->basicShEscaping($getUrl);
85 if ($request->getSession()->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)
86 != $request->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME)) {
87 $text = _(
"This seems to be a resent file.");
88 return array(
false, $text, $description);
91 if (empty($folderId)) {
92 $text = _(
"Invalid Folder.");
93 return array(
false, $text, $description);
96 $public = $request->get(
'public');
99 $Name =
trim($request->get(
'name'));
101 $Name = basename($getUrl);
103 $ShortName = basename($Name);
104 if (empty($ShortName)) {
109 $uploadMode = (1 << 2);
112 $uploadId =
JobAddUpload($userId, $groupId, $ShortName, $getUrl,
113 $description, $uploadMode, $folderId, $publicPermission);
114 if (empty($uploadId)) {
115 $text = _(
"Failed to insert upload record");
116 return array(
false, $text, $description);
120 $jobpk = JobAddJob($userId, $groupId,
"wget", $uploadId);
121 if (empty($jobpk) || ($jobpk < 0)) {
122 $text = _(
"Failed to insert job record");
123 return array(
false, $text, $description);
126 $VCSType =
trim($request->get(
'vcstype'));
127 $VCSType = $this->basicShEscaping($VCSType);
128 $jq_args =
"$uploadId - $getUrl $VCSType ";
130 $Username =
trim($request->get(
'username'));
131 $Username = $this->basicShEscaping($Username);
132 if (!empty($Username)) {
133 $jq_args .=
"--username $Username ";
136 $Passwd =
trim($request->get(
'passwd'));
137 $Passwd = $this->basicShEscaping($Passwd);
138 if (!empty($Passwd)) {
139 $jq_args .=
"--password $Passwd ";
142 $Branch =
trim(explode(
' ',
trim($request->get(
'branch')))[0]);
143 if (!empty($Branch) && strcasecmp($VCSType,
'git') == 0) {
144 $jq_args .=
"--single-branch --branch '$Branch'";
147 $jobqueuepk =
JobQueueAdd($jobpk,
"wget_agent", $jq_args, NULL, NULL);
148 if (empty($jobqueuepk)) {
149 $text = _(
"Failed to insert task 'wget_agent' into job queue");
150 return array(
false, $text, $description);
153 $unpackplugin = &$Plugins[plugin_find_id(
"agent_unpack") ];
154 $unpackArgs = intval($request->get(
'scm')) == 1 ?
'-I' :
'';
155 $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array(
"wget_agent"), $unpackArgs);
156 if ($ununpack_jq_pk < 0) {
157 return array(
false, _($ErrorMsg), $description);
160 $adj2nestplugin = &$Plugins[plugin_find_id(
"agent_adj2nest") ];
161 $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadId, $ErrorMsg, array());
162 if ($adj2nest_jq_pk < 0) {
163 return array(
false, _($ErrorMsg), $description);
171 if (empty($status)) {
172 $msg .= _(
"Is the scheduler running? ");
175 $text = _(
"The upload");
176 $text1 = _(
"has been queued. It is");
177 $msg .=
"$text $Name $text1 ";
178 $keep =
"<a href='$Url'>upload #" . $uploadId .
"</a>.\n";
179 return array(
true, $msg.$keep, $description, $uploadId);
GetRunnableJobList()
Get runnable job list, the process is below:
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
AgentCheckBoxDo($job_pk, $upload_pk)
Assume someone called AgentCheckBoxMake() and submitted the HTML form. Run AgentAdd() for each of the...
handleUpload(Request $request)
Process the upload request.
Upload from some Version Conntrol System using the UI.
render($templateName, $vars=null, $headers=null)
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
handleView(Request $request, $vars)
static getGroupId()
Get the current user's group id.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE)
Insert a new upload record, and update the foldercontents table.
char * trim(char *ptext)
Trimming whitespace.