当前位置: 首页>>代码示例>>PHP>>正文


PHP Problem::save方法代码示例

本文整理汇总了PHP中Problem::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Problem::save方法的具体用法?PHP Problem::save怎么用?PHP Problem::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Problem的用法示例。


在下文中一共展示了Problem::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['time_limit' => 'required', 'memory_limit' => 'required', 'name' => 'required', 'description' => 'required', 'input' => 'required', 'output' => 'required', 'sampleIn' => 'required', 'sampleOut' => 'required', 'tags' => 'required', 'testIn' => 'required', 'testOut' => 'required']);
     $problem = new Problem();
     $problem->name = $request->input('name');
     $problem->description = $request->input('description');
     $problem->input = $request->input('input');
     $problem->output = $request->input('output');
     $problem->sample_input = $request->input('sampleIn');
     $problem->sample_output = $request->input('sampleOut');
     $problem->time_limit = $request->input('time_limit');
     $problem->memory_limit = $request->input('memory_limit');
     $problem->save();
     $problemFolder = public_path() . '/' . $problem->id;
     File::makeDirectory($problemFolder);
     File::put($problemFolder . '/sample.in', $problem->sample_input);
     File::put($problemFolder . '/sample.out', $problem->sample_output);
     $testIn = $request->file('testIn');
     $testIn->move($problemFolder, 'test.in');
     $testOut = $request->file('testOut');
     $testOut->move($problemFolder, 'test.out');
     /*
     $inputFiles = $problem->id;
     $inputFilesFolder = public_path() . '/' . $inputFiles;
     $outputFiles = $problem->id;
     $outputFilesFolder = public_path() . '/' . $outputFiles;
     
     $fileinput=$request->file('inputfile');
     $filenameInput='sample.in';
     $fileinput->move($inputFilesFolder, $filenameInput);
     File::put($inputFilesFolder.'/samplei.in','John DoeIN');
     $fileoutput=$request->file('outputfile');
     $filenameOut=time().'.'.$fileoutput->getClientOriginalExtension();
     $filenameOut='test.in';
     $fileoutput->move($outputFilesFolder, $filenameOut);
     File::put($outputFilesFolder.'/sampleo.out','John DoeOut');
     */
     foreach (explode(',', $request->input('tags2')) as $tag_id) {
         DB::table('problemhastags')->insert(['problem_id' => $problem->id, 'tag_id' => $tag_id]);
     }
     return redirect()->action('ProblemController@index');
 }
开发者ID:patitoteam,项目名称:PatitoOnlineJudge,代码行数:48,代码来源:ProblemController.php

示例2: run

 function run()
 {
     $problem = new Problem();
     $problem->station_code = 'POCG  ';
     $problem->data_type = 'RAIN';
     $problem->problem_type = 'BD';
     $problem->start_datetime = date('Y-m-d 09:00');
     $problem->end_datetime = date('Y-m-d 10:10');
     $problem->num = 7;
     $problem->status = 'undefined';
     if (!$problem->save()) {
         Log::info('Unable to create problem ' . $problem->station_code, (array) $problem->errors());
     } else {
         Log::info('Created problem "' . $problem->station_code . '" <' . $problem->start_datetime . '>');
     }
     $problem = new Problem();
     $problem->station_code = 'NAPJ  ';
     $problem->data_type = 'RAIN';
     $problem->problem_type = 'BD';
     $problem->start_datetime = date('Y-m-d 19:00', time() - 24 * 60 * 60);
     $problem->end_datetime = date('Y-m-d 19:10', time() - 24 * 60 * 60);
     $problem->num = 1;
     $problem->status = 'undefined';
     if (!$problem->save()) {
         Log::info('Unable to create problem ' . $problem->station_code, (array) $problem->errors());
     } else {
         Log::info('Created problem "' . $problem->station_code . '" <' . $problem->start_datetime . '>');
     }
     $problem = new Problem();
     $problem->station_code = 'WSTG  ';
     $problem->data_type = 'WATER';
     $problem->problem_type = 'BD';
     $problem->start_datetime = date('Y-m-d 09:00');
     $problem->end_datetime = date('Y-m-d 10:10');
     $problem->num = 7;
     $problem->status = 'undefined';
     if (!$problem->save()) {
         Log::info('Unable to create problem ' . $problem->station_code, (array) $problem->errors());
     } else {
         Log::info('Created problem "' . $problem->station_code . '" <' . $problem->start_datetime . '>');
     }
     $problem = new Problem();
     $problem->station_code = 'VLGE30';
     $problem->data_type = 'WATER';
     $problem->problem_type = 'BD';
     $problem->start_datetime = date('Y-m-d 19:00', time() - 24 * 60 * 60);
     $problem->end_datetime = date('Y-m-d 19:10', time() - 24 * 60 * 60);
     $problem->num = 1;
     $problem->status = 'undefined';
     if (!$problem->save()) {
         Log::info('Unable to create problem ' . $problem->station_code, (array) $problem->errors());
     } else {
         Log::info('Created problem "' . $problem->station_code . '" <' . $problem->start_datetime . '>');
     }
 }
开发者ID:withlovee,项目名称:HAII,代码行数:55,代码来源:DatabaseSeeder.php

示例3: fire

 public function fire($job, $data)
 {
     $output = new Symfony\Component\Console\Output\ConsoleOutput();
     $node = Node::find($data['message']['node_id']);
     $s3 = \Aws\S3\S3Client::factory(array('key' => 'AKIAIUCV4E2L4HDCDOUA', 'secret' => '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', 'region' => 'us-east-1'));
     $all_keys = Key::where('integration_id', '=', $data['message']['integration_id'])->get();
     foreach ($all_keys as $pem_key_reference) {
         if ($pem_key_reference->remote_url) {
             $unique_key_name = rand(0, 9999) . $pem_key_reference->remote_url;
             $key_bucket = App::isLocal() ? 'devkeys.nosprawl.software' : 'keys.nosprawl.software';
             $s3->getObject(array('Bucket' => $key_bucket, 'Key' => $pem_key_reference->remote_url, 'SaveAs' => '/tmp/' . $unique_key_name));
             // Shouldn't need these two lines at all.
             exec('chmod 400 /tmp/' . $unique_key_name);
             $empty = null;
             $s3_resource_root = App::isLocal() ? 'http://agent.nosprawl.software/dev/' : 'http://agent.nosprawl.software/';
             $latest_version = exec("curl -s " . $s3_resource_root . "latest", $empty);
             $latest_version_url = $s3_resource_root . $latest_version;
             $ssh = new Net_SSH2($node->public_dns_name);
             $ssh->enableQuietMode();
             $ssh->enablePTY();
             $key = new Crypt_RSA();
             $key->loadKey(file_get_contents('/tmp/' . $unique_key_name));
             exec('rm -rf /tmp/' . $unique_key_name);
             if (!$ssh->login($pem_key_reference->username, $key)) {
                 continue;
             } else {
                 $possible_installers = ["yum", "apt-get"];
                 foreach ($possible_installers as $possible_installer) {
                     $installer_check_result = false;
                     $found = false;
                     $ssh->exec("sudo " . $possible_installer . " -y install ruby");
                     $install_result = $ssh->read();
                     $output->writeln($install_result);
                     $install_exit_status = $ssh->getExitStatus();
                     if ($install_exit_status == 0) {
                         Queue::push('DeployAgentToNode', array('message' => array('node_id' => $node->id, 'integration_id' => $node->integration->id)));
                         return $job->delete();
                     }
                 }
             }
         } else {
             $output->writeln("This is what we do if all we have is a password.");
             continue;
         }
     }
     // If we got to this point we were unable to install Curl automatically.
     $problem = new Problem();
     $problem->description = "Couldn't install Curl.";
     $problem->reason = "Unable to automatically install Curl. Please install it manually.";
     $problem->node_id = $node->id;
     $problem->save();
     $remediation = new Remediation();
     $remediation->name = "Retry Deployment";
     $remediation->queue_name = "DeployAgentToNode";
     $remediation->problem_id = $problem->id;
     $remediation->save();
     $remediation = new Remediation();
     $remediation->name = "Cancel";
     $remediation->queue_name = "CancelDeployAgentToNode";
     $remediation->problem_id = $problem->id;
     $remediation->save();
     return $job->delete();
 }
开发者ID:crudbug,项目名称:Dashboard,代码行数:63,代码来源:InstallCurlAndRetryDeployment.php

示例4: fire

 public function fire($job, $data)
 {
     $output = new Symfony\Component\Console\Output\ConsoleOutput();
     $node = Node::find($data['message']['node_id']);
     // Make sure node exists
     if (!$node) {
         $output->writeln("node doesn't exist anymore. no need for this job.");
         return $job->delete();
     }
     // Make sure node isn't terminated
     /*if($node->service_provider_status == "terminated") {
     			return $job->delete();
     		}*/
     // Make sure node is running
     if ($node->service_provider_status != "running") {
         return $job->release();
         $output->writeln("node is not running");
     }
     // Keys are always stored on S3. This is the NoS account.
     $s3 = \Aws\S3\S3Client::factory(array('key' => 'AKIAIUCV4E2L4HDCDOUA', 'secret' => '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', 'region' => 'us-east-1'));
     $all_keys = Key::where('integration_id', '=', $data['message']['integration_id'])->get();
     $unique_key_name = null;
     $cmdout = null;
     // Make sure the user has added credentials for this integration
     if ($all_keys->isEmpty()) {
         $problem = new Problem();
         $problem->description = "Couldn't deploy agent";
         $problem->reason = "No credentials added for this integration.<br /><br />You can manage your integration credentials on the <a href='#'>integrations</a> page.<br />Or <a href='#'>deploy manually</a>.";
         $problem->node_id = $node->id;
         $problem->long_message = true;
         $problem->save();
         $remediation = new Remediation();
         $remediation->name = "Cancel";
         $remediation->queue_name = "CancelDeployAgentToNode";
         $remediation->problem_id = $problem->id;
         $remediation->save();
         $remediation = new Remediation();
         $remediation->name = "Retry";
         $remediation->queue_name = "DeployAgentToNode";
         $remediation->problem_id = $problem->id;
         $remediation->save();
         return $job->delete();
     }
     $eventually_logged_in = false;
     foreach ($all_keys as $pem_key_reference) {
         if ($pem_key_reference->remote_url) {
             $unique_key_name = rand(0, 9999) . $pem_key_reference->remote_url;
             $key_bucket = App::isLocal() ? 'devkeys.nosprawl.software' : 'keys.nosprawl.software';
             $s3->getObject(array('Bucket' => $key_bucket, 'Key' => $pem_key_reference->remote_url, 'SaveAs' => '/tmp/' . $unique_key_name));
             exec('chmod 400 /tmp/' . $unique_key_name);
             $empty = null;
             $s3_resource_root = App::isLocal() ? 'http://agent.nosprawl.software/dev/' : 'http://agent.nosprawl.software/';
             $latest_version = exec("curl -s " . $s3_resource_root . "latest", $empty);
             $latest_version_url = $s3_resource_root . $latest_version;
             $ssh = new Net_SSH2($node->public_dns_name);
             $ssh->enableQuietMode();
             $ssh->enablePTY();
             $key = new Crypt_RSA();
             $key->loadKey(file_get_contents('/tmp/' . $unique_key_name));
             exec('rm -rf /tmp/' . $unique_key_name);
             if (!$ssh->login($pem_key_reference->username, $key)) {
                 $output->writeln("ssh fail.");
                 continue;
             } else {
                 $output->writeln("we are in ssh just fine.");
                 // Let's look for any problems running sudo first.
                 $ssh->exec("sudo whoami");
                 $exit_status = $ssh->getExitStatus();
                 if (!$exit_status && $exit_status != 0) {
                     // User can't sudo without a password. We can't auto-install.
                     $problem = new Problem();
                     $problem->description = "Couldn't deploy agent";
                     $problem->reason = "User '" . $pem_key_reference->username . "' doesn't have passwordless sudo priviliges. Please either enable  it or <a class='problem_cta_btn' href='#'>Manually deploy the NoSprawl Agent</a>";
                     $problem->node_id = $node->id;
                     $problem->long_message = true;
                     $problem->save();
                     $remediation = new Remediation();
                     $remediation->name = "Cancel";
                     $remediation->queue_name = "CancelDeployAgentToNode";
                     $remediation->problem_id = $problem->id;
                     $remediation->save();
                     $remediation = new Remediation();
                     $remediation->name = "Retry";
                     $remediation->queue_name = "DeployAgentToNode";
                     $remediation->problem_id = $problem->id;
                     $remediation->save();
                     return $job->delete();
                 }
                 $result = $ssh->read();
                 $output->writeln($result);
                 // Check for problems with curl
                 $ssh->exec("curl --help");
                 $curl_result = $ssh->read();
                 $curl_exit_status = $ssh->getExitStatus();
                 if ($curl_exit_status != 0) {
                     $problem = new Problem();
                     $problem->description = "Couldn't deploy agent";
                     $problem->reason = "cURL isn&rsquo;t installed.";
                     $problem->node_id = $node->id;
                     $problem->save();
//.........这里部分代码省略.........
开发者ID:crudbug,项目名称:Dashboard,代码行数:101,代码来源:DeployAgentToNode.php


注:本文中的Problem::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。