Exemple #1
0
}
$ssh->exec('umask 0002 ; mkdir -p ' . $job_path);
// dprint($of, "job_path = $job_path\n");
$job_path_output = tempdir($ssh, $job_path);
// dprint($of, "job_path_output = $job_path_output\n");
// replace ${OUTPUT} pattern in the command and in the parameters
$command = str_replace("{OUTPUT}", $job_path, $command);
$command = str_replace("{FEED_ID}", $feed_id, $command);
$command = str_replace("{USER_ID}", $user_id, $command);
$parameters = str_replace("{OUTPUT}", $job_path, $parameters);
$parameters = str_replace("{FEED_ID}", $feed_id, $parameters);
$parameters = str_replace("{USER_ID}", $user_id, $parameters);
// add meta information to the feed
FeedC::addMetaS($feed_id, 'parameters', $parameters, 'simple');
// add owner
FeedC::addMetaS($feed_id, 'root_id', (string) $feed_id, 'extra');
// append the log files to the command
$command .= ' >> ' . $job_path_output . '/chris.std 2> ' . $job_path_output . '/chris.err';
// create the chris.env and chris.run file
$envfile = joinPaths($job_path_output, 'chris.env');
$runfile = joinPaths($job_path_output, 'chris.run');
// dprint($of, "command = $command\n");
// dprint($of, "runfile = $runfile\n");
$setStatus = '';
// retry 5 times with a 5 seconds delay
// connection timeout: 5s
// max query time: 30
if ($status != 100) {
    //  $setStatus .= '/bin/sleep $(( RANDOM%=10 )) ; /usr/bin/curl --retry 5 --retry-delay 5 --connect-timeout 5 --max-time 30 -v -k --data ';
    $setStatus .= '/bin/sleep $(( RANDOM%=10 )) ; /usr/bin/curl -k --data ';
}
 public static function share($feed_ids, $ownerid, $ownername, $targetname, &$ssh_connection)
 {
     foreach ($feed_ids as $feed_id) {
         // get target user id
         $userMapper = new Mapper('User');
         $userMapper->filter('username = (?)', $targetname);
         $userResult = $userMapper->get();
         if (count($userResult['User']) >= 1) {
             // get feed to be shared
             $feedMapper = new Mapper('Feed');
             $feedMapper->filter('id = (?)', $feed_id);
             $feedResult = $feedMapper->get();
             if (count($feedResult['Feed']) >= 1) {
                 $feedResult['Feed'][0]->id = 0;
                 $feedResult['Feed'][0]->user_id = $userResult['User'][0]->id;
                 $feedResult['Feed'][0]->time = microtime(true);
                 $feedResult['Feed'][0]->favorite = 0;
                 $new_id = Mapper::add($feedResult['Feed'][0]);
                 // get parameters, owner meta information
                 $metaMapper = new Mapper('Meta');
                 // OR confiton between all filters
                 $metaMapper->filter('', '', 0, 'OR');
                 // first filters
                 $metaMapper->filter('name = (?)', 'root_id', 1);
                 $metaMapper->filter('target_id = (?)', $feed_id, 1);
                 $metaMapper->filter('target_type = (?)', 'feed', 1);
                 // second filters
                 $metaMapper->filter('name = (?)', 'parameters', 2);
                 $metaMapper->filter('target_id = (?)', $feed_id, 2);
                 $metaMapper->filter('target_type = (?)', 'feed', 2);
                 // second filters
                 $metaMapper->filter('name = (?)', 'pid', 3);
                 $metaMapper->filter('target_id = (?)', $feed_id, 3);
                 $metaMapper->filter('target_type = (?)', 'feed', 3);
                 // get results
                 $metaResult = $metaMapper->get();
                 // for earch result, create same meta with different target id
                 if (count($metaResult['Meta']) >= 1) {
                     foreach ($metaResult['Meta'] as $k0 => $v0) {
                         $v0->id = 0;
                         $v0->target_id = $new_id;
                         // make sure to properly update the root_id
                         if ($v0->name == 'root_id') {
                             $v0->value = $feed_id;
                         }
                         Mapper::add($v0);
                     }
                 }
                 // add sharer
                 FeedC::addMetaS($new_id, 'sharer_id', (string) $ownerid, 'simple');
                 // link files on file system
                 $targetDirectory = CHRIS_USERS . '/' . $ownername . '/' . $feedResult['Feed'][0]->plugin . '/' . $feedResult['Feed'][0]->name . '-' . $feed_id;
                 $destinationDirectory = CHRIS_USERS . '/' . $targetname . '/' . $feedResult['Feed'][0]->plugin;
                 if (!is_dir($destinationDirectory)) {
                     // 777? 775
                     $old = umask();
                     umask(00);
                     mkdir($destinationDirectory, 0775, true);
                     umask($old);
                 }
                 $destinationDirectory .= '/' . $feedResult['Feed'][0]->name . '-' . $new_id;
                 // just a link?
                 symlink($targetDirectory, $destinationDirectory);
                 // we need to change the permission of the target directory to 777 (as the owner)
                 // so that the other user can write to this folder
                 // but only if the targetDirectory is a directory and not a link (a link means it was re-shared)
                 if (is_dir($targetDirectory)) {
                     $ssh_connection->exec('chmod -R 777 ' . $targetDirectory);
                 }
                 //if(!is_dir($destinationDirectory)){
                 //  recurse_copy($targetDirectory, $destinationDirectory);
                 //}
             } else {
                 return "Invalid feed id: " . $feed_id;
             }
         } else {
             return "Invalid target name: " . $targetname;
         }
     }
     return '';
 }