getMetaData() public method

Returns file and directory information
public getMetaData ( string $path, boolean $list = true, string $hash = null, integer $fileLimit = null, string $root = null ) : array | true
$path string Path to receive information from
$list boolean When set to true, this method returns information from all files in a directory. When set to false it will only return infromation from the specified directory.
$hash string If a hash is supplied, this method simply returns true if nothing has changed since the last request. Good for caching.
$fileLimit integer Maximum number of file-information to receive
$root string Use this to override the default root path (sandbox/dropbox)
return array | true
 public function dir_opendir($path, $options)
 {
     $path = $this->initPath($path);
     $metadata = self::$dropbox->getMetaData($path);
     AJXP_Logger::debug("CONTENT for {$path}", $metadata);
     self::$crtDirContent = $metadata["contents"];
     return true;
 }
Exemplo n.º 2
0
 public function dir_opendir($path, $options)
 {
     $path = $this->initPath($path);
     $metadata = self::$dropbox->getMetaData($path);
     AJXP_Logger::debug(__CLASS__, __FUNCTION__, "CONTENT for {$path}", $metadata);
     self::$crtDirContent = $metadata["contents"];
     if (!is_array(self::$crtDirContent)) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * @param \Dropbox_API $dropbox
  */
 function it_fails_checking_if_key_is_dir_when_dropbox_throws_exception($dropbox)
 {
     $dropbox->getMetaData('filename', false)->willThrow(new \RuntimeException('some exception'));
     $this->shouldThrow(new \RuntimeException('some exception'))->duringIsDirectory('filename');
 }
  protected function doProcess($arguments = array(), $options = array())
  {

    # DISABLED
    //$this->logBlock('DISABLED.', 'ERROR');
    // exit;
    
    
    
    

    if (!$options['go']) 
      $this->logBlock('Running in dry mode, no files will be uploaded.', 'ERROR');

    $consumerKey = sfConfig::get("app_dropbox_consumer_key");
    $consumerSecret = sfConfig::get("app_dropbox_consumer_secret");
    $token = sfConfig::get("app_dropbox_token");
    $token_secret = sfConfig::get("app_dropbox_token_secret");
    $dropboxRoot = sfConfig::get("app_dropbox_root");
    
    ProjectConfiguration::registerDropboxAPI();
    
    // If the PHP OAuth extension is not available, you can try
    // PEAR's HTTP_OAUTH instead.
    $oauth = new Dropbox_OAuth_PEAR($consumerKey, $consumerSecret);
    $dropbox = new Dropbox_API( $oauth );
    $tokens = array(
                "token"        => $token,
                "token_secret" => $token_secret
              );
    $oauth->setToken($tokens);


    // get DROPBOX directory listing
    $metadata = $dropbox->getMetaData($dropboxRoot, $list = true, $hash = null, $fileLimit = null, $root = null);
    $dropbox_list = array();
    
    $this->logBlock(sprintf("Connected dropbox in %s", $dropboxRoot), 'COMMENT');
    
    if (is_array( $metadata['contents'] )) {
      foreach( $metadata['contents'] as $info)
      {
                
        /*
        if ($info["mime_type"] == "application/pdf") {
          $filename = strtolower( basename( $info["path"] ) );
          */
          
          $filename = strtolower( basename( $info["path"] ) );

          // https://www.dropbox.com/developers/docs
          $timestamp = strtotime($info["modified"]);
          
          /*
          $ftime = strptime($info["modified"], "%a, %d %b %Y %H:%M:%S %z");
          $timestamp = mktime( 
                    $ftime['tm_hour'], 
                    $ftime['tm_min'], 
                    $ftime['tm_sec'], 
                    1 , 
                    $ftime['tm_yday'] + 1, 
                   $ftime['tm_year'] + 1900 
                 );
          */
         
          // time zone problem ?!?
          //$timestamp = strtotime("+2 hours", $timestamp);
          
          $dropbox_list["$filename"] = $timestamp;
        // }
      }
    }
    
    // compare DROPBOX contents to "live" files
    $push_files = array();
    $dir = sfConfig::get('sf_data_dir').sfConfig::get('app_rockstep_pdf_dir');
    $weeds = array('.', '..','.DS_Store'); 
    $directory = array_diff(scandir($dir), $weeds); 

    if (!$options['force']) {
      $this->logBlock(sprintf("Checking %d files in %s", count($directory), $dir), 'COMMENT');
    } else {
      $this->logBlock(sprintf("Pushing %d files from %s", count($directory), $dir), 'COMMENT');
    }
    
    foreach( $directory as $id => $filename ) {
      if (is_file($dir.$filename)) {
        if (!$options['force']) {
          if (array_key_exists(strtolower($filename), $dropbox_list)) {

            $this->logSection('file', sprintf("%s %s %s", $filename, filemtime($dir.$filename), $dropbox_list[strtolower($filename)] ));

            //echo date('Y-m-d H:m:s u', strtotime( $dropbox_list[strtolower($filename)] ))."--".date('Y-m-d H:m:s u', filemtime($dir.$filename));

            if ( filemtime($dir.$filename) > $dropbox_list[strtolower($filename)] ) {

              //echo date('Y-m-d H:m:s', $dropbox_list[strtolower($filename)] )."--".date('Y-m-d H:m:s', filemtime($dir.$filename));

              $push_files[] = $filename;
            }
          } else {
            $push_files[] = $filename;
          }
        } else {
          $push_files[] = $filename;
        }
      }
    }
    
    // PUSH to dropbox
    $error = 0; $success = 0;
    if (count($push_files) == 0) {
        $this->logBlock("Everything is up to date.", 'INFO');
        $this->task->setErrorCode(304);
        $this->setOk();
    } else {
      if (!$options['force'])
        $this->logBlock(sprintf("%d files have been modified", count($push_files)), 'INFO');
      foreach ($push_files as $filename) {
        if ($options['go']) {
         // sync
         
          $this->logBlock(sprintf("try: %s => %s", $dir.$filename, $dropboxRoot.$filename), 'INFO');
         $result = $dropbox->putFile($dropboxRoot.$filename, $dir.$filename);
                  
         if($result['httpStatus'] == 200 ) {
         
            // set datemodified to the dropbox-date
            $metadata = $dropbox->getMetaData($dropboxRoot.$filename, $list = true, $hash = null, $fileLimit = null, $root = null);
            touch($dir.$filename, strtotime($metadata['modified']) );

            //echo date('Y-m-d H:m:s u', strtotime($metadata['modified']))."--".date('Y-m-d H:m:s u', filemtime($dir.$filename));
            //echo strtotime($metadata['modified']);
            
            $this->logSection('file+', sprintf("%s", $filename));
            $success += 1;
            
          } else {
            $this->logSection('error', sprintf("%s", $filename));
            $error += 1;
          }
        
        } else {
          // dry run
          $this->logSection('file+', sprintf("%s", $filename));
          $success += 1;
        }
      }
      
      if ($options['go']) {
        if ($error > 0) {
          $this->logBlock(sprintf('Error Uploading on %d out of %d Files', $error, $success, $dropboxRoot), 'ERROR');
          $this->task->setErrorCode(500);
          $this->setNOk($error);
        } else {
          $this->logBlock(sprintf('Uploaded %d Files to %s', $success, $dropboxRoot), 'INFO');
          $this->task->setErrorCode(200);
          $this->setOk();
        }
      } else {
        // dry run
      } 
    }
    
  }
Exemplo n.º 5
0
 static function DropboxUpload($fileid)
 {
     /*
      * This script shoud upload a file to a 
      * special folder in the users dropbox.
      * The session should bestarted and the
      * user should be logged in already.
      *
      * @author Nils Bussmann <*****@*****.**>
      * @date   05.02.2011
      * @param  filename should be the path to the local file 
      * @param  folder the folder in the dropbox
      *
      * @return  fail:   filename    if something went wrong
      *          success:filename    if everything went right
      *          exists: filename    if the file already exists
      */
     if (isset($fileid)) {
         session_start();
         //generate filename, filepath, intended_path
         //get filename from database
         $db = \DBManager::get();
         $query = "   SELECT dokument_id, range_id, filename, seminar_id\n\t\t\t\t\t\tFROM    dokumente\n\t\t\t\t\t\tWHERE   dokumente.dokument_id =  '{$fileid}' ";
         $file_result = $db->query($query)->fetchAll();
         //get folder from database
         $seminar_id = $file_result[0]["seminar_id"];
         $range_id = $file_result[0]["range_id"];
         $query = "   SELECT  folder.folder_id, folder.name as folder_name, seminare.Seminar_id, seminare.name as seminar_name\n\t\t\t\t\t\tFROM    folder\n\t\t\t\t\t\tJOIN    seminare ON seminare.Seminar_id  =  '{$seminar_id}' \n\t\t\t\t\t\tWHERE   folder.folder_id =  '{$range_id}' ";
         $folder_result = $db->query($query)->fetchAll();
         // repart the important strings
         $filename = \Helper::cleanFilename($file_result[0]["filename"]);
         $file = $GLOBALS['UPLOAD_PATH'] . "/" . substr($fileid, 0, 2) . "/" . $fileid;
         $folder = \Helper::cleanFilename($folder_result[0]["seminar_name"] . "/" . $folder_result[0]["folder_name"]);
         //check if everthing is allright
         if (!isset($filename) || !isset($file) || !isset($folder)) {
             if (!isset($filename)) {
                 $filename = fileid;
             }
             return "fail:" . $filename;
         }
         /* start interaction width dropbox
            session shoud be started, user should logged in
            Please supply your own consumer key and consumer secret */
         $consumerKey = '5wty9mf06gcuco0';
         $consumerSecret = 'hveok3hllw48hji';
         try {
             $oauth = new \Dropbox_OAuth_PEAR($consumerKey, $consumerSecret);
             $dropbox = new \Dropbox_API($oauth, \Dropbox_API::ROOT_SANDBOX);
             $oauth->setToken($_SESSION['oauth_tokens']);
             //Check if the directories are created and
             //single subfolders in $folders
             $folders = explode("/", $folder);
             $checked_path = "/";
             foreach ($folders as $subfolder) {
                 $found_folder = false;
                 $info = $dropbox->getMetaData($checked_path);
                 foreach ($info["contents"] as $meta_info) {
                     if ($meta_info["is_dir"] == 1 && \Helper::endsWith($meta_info["path"], $subfolder)) {
                         $found_folder = true;
                         break;
                     }
                 }
                 if (!$found_folder) {
                     $dropbox->createFolder($checked_path . "/" . $subfolder);
                 }
                 if ($checked_path == "/") {
                     $checked_path .= $subfolder;
                 } else {
                     $checked_path .= "/" . $subfolder;
                 }
             }
             //depending folder exists
             //check if file already exisits
             $found = false;
             // $found shows if file already exisits
             $info = $dropbox->getMetaData($folder);
             foreach ($info["contents"] as $array_files) {
                 if (strpos($array_files["path"], $filename) != false) {
                     $ausgabe = "exists:" . $filename;
                     $found = true;
                 }
             }
             //Upload the file if nessasery
             if ($found == false) {
                 if ($dropbox->putFile($folder . "/" . $filename, $file)) {
                     $ausgabe = "success:" . $filename;
                 } else {
                     $ausgabe = "fail:" . $filename;
                 }
             }
         } catch (Exception $e) {
             // something went wrong, not specified
             // to specify the error there are other exeptions to catch
             $ausgabe = "fail:" . $filename;
         } catch (HTTP_OAuth_Exception $e) {
             $ausgabe = "fail:" . $filename;
         }
     } else {
         $ausgabe = "fail:" . $filename;
     }
     return $ausgabe;
 }
Exemplo n.º 6
0
 /**
  * Returns file and directory information
  *
  * @param string $path Path to receive information from
  * @param bool $list When set to true, this method returns information from all files in a directory. When set to false it will only return infromation from the specified directory.
  * @param string $hash If a hash is supplied, this method simply returns true if nothing has changed since the last request. Good for caching.
  * @param int $fileLimit Maximum number of file-information to receive
  * @param string $root Use this to override the default root path (sandbox/dropbox)
  * @return array|true
  */
 public function getMetaData($path, $list = true, $hash = null, $fileLimit = null, $root = null)
 {
     return $this->dropbox->getMetaData($path, $list, $hash, $fileLimit, $root);
 }