/**
     * This method does the initial work initializing the repository
     */
    public function init_repo() {
        global $USER, $SESSION;

        // Check if Alfresco is enabled, configured and running first
        $options = array(
            'ajax' => false,
            'name' => 'elis files phpunit test',
            'type' => 'elisfiles'
        );

        if (!$repo = new repository_elisfiles('elisfiles', context_system::instance(), $options)) {
            $this->markTestSkipped('Repository not configured or enabled');
        }

        // Check if we need to create a user and then force the repository connection to be reinitialized.
        if (empty($repo->elis_files->uuuid)) {
            $USER->email = '*****@*****.**';
            $this->assertTrue($repo->elis_files->migrate_user($USER, 'temppass'));
            unset($SESSION->repo);
            self::$testusercreated = $USER->username;
            $repo = new repository_elisfiles('elisfiles', context_system::instance(), $options);
        }

        $filename = self::generate_temp_file(1);
        $uploadresponse = elis_files_upload_file('', $filename, $repo->elis_files->uuuid);

        unlink($filename);
        $this->fileuuid = ($uploadresponse && !empty($uploadresponse->uuid)) ? $uploadresponse->uuid : '';

        $this->repo = $repo;
    }
Exemple #2
0
/**
 * Move files for a web script into the Alfresco repository and refresh the list of currently
 * installed web scripts.
 *
 * @param $CFG
 * @param array  $files An array of full file paths to install.
 * @param string $uuid  The node UUID to install the files in.
 * @return bool True on success, False otherwise.
 */
function elis_files_install_web_script($files, $uuid) {
    global $CFG;

    $status = true;

    if (!is_array($files)) {
        debugging('Not array');
        return false;
    }

    foreach ($files as $file) {
        if (!is_file($file)) {
            debugging('Not a file: ' . $file);
            return false;
        }

        $status = $status && elis_files_upload_file('', $file, $uuid);
    }

    if ($status) {
        sleep(2);
        $url = elis_files_base_url() . '/?reset=on';

    /// Prepare curl session
        $session = curl_init($url);

        curl_setopt($session, CURLOPT_VERBOSE, true);

    /// Don't return HTTP headers. Do return the contents of the call
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($session, CURLOPT_POST, true);

        elis_files_set_curl_timeouts($session);

    /// Make the call
        $return_data = curl_exec($session);

    /// Get return http status code
        $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);

    /// Close HTTP session
        curl_close($session);

        if ($httpcode !== 200) {
            debugging('HTTP code: ' . $httpcode);
            debugging($return_data);
            $status = false;
        }
    }

    return $status;
}
Exemple #3
0
    /**
     * Test that uploading a file to a specific folder generates a valid response
     * @dataProvider file_size_provider
     */
    public function test_upload_to_folder_and_get_response($mb) {
        $this->resetAfterTest(true);
        $this->setup_test_data_xml();

        $repo = repository_factory::factory('elisfiles');

        // Used data provider to just generate one file
        $filesize = $mb * ONE_MB_BYTES;
        $filename = $this->generate_temp_file($mb);

        // Upload to a folder
        $uploadresponse = elis_files_upload_file('', $filename, $repo->muuid);

        unlink($filename);

        // Verify that we get a valid response
        $this->assertNotEquals(false, $uploadresponse);
        // Verify that response has a uuid
        $this->assertObjectHasAttribute('uuid', $uploadresponse);

        // Get info on the uploaded file's uuid...
        $response = $repo->get_info($uploadresponse->uuid);

        // Cleanup the uploaded file
        $this->cleanup_files($repo->muuid);

        // Verify that response has a type
        $this->assertObjectHasAttribute('type', $response);
        // Verify that type is folder
        $this->assertEquals(ELIS_files::$type_document, $response->type);
        // Verify that title is set
        $this->assertObjectHasAttribute('title', $response);
        // Verify that created is set
        $this->assertObjectHasAttribute('created', $response);
        // Verify that modified is set
        $this->assertObjectHasAttribute('modified', $response);
        // Verify that summary is set
        $this->assertObjectHasAttribute('summary', $response);
        // Verify that Owner is set
        $this->assertObjectHasAttribute('owner', $response);
    }
Exemple #4
0
/**
 * Upload the contents of an entire directory onto the Alfresco server,
 * moving throuh any sub-directories recursively as needed.
 *
 * @uses $CFG
 * @param string $path     The local filesystem path to upload contents from.
 * @param string $uuid     The folder UUID value on Alfresco to send contents.
 * @param bool   $recurse  Whether to recurse into subdirecotires (default: on).
 * @param bool   $useadmin Set to false to make sure that the administrative user configured in
 *                         the plug-in is not used for this operation (default: true).
 * @return bool True on success, False otherwise.
 */
    function upload_dir($path, $uuid, $recurse = true, $useadmin = true) {
        if (ELIS_FILES_DEBUG_TRACE) mtrace('upload_dir(' . $path . ', ' . $uuid . ', ' . $recurse . ')');
        if (ELIS_FILES_DEBUG_TIME) $start = microtime(true);

        if (!$this->get_defaults()) {
            return false;
        }
    /// Make sure the location we are meant to upload files and create new
    /// directories actually exists and is a folder, not a content node.

        if (!$this->is_dir($uuid)) {
            return false;
        }

    /// Make sure the local path is a directory.
        if (!is_dir($path)) {
            return false;
        }

        $path .= ($path[strlen($path) - 1] != '/' ? '/' : '');

    /// Parse through the directory, creating folders and content nodes for
    /// each directory and file we encounter.
        $dh = opendir($path);

        while ($file = readdir($dh)) {
            if ($file == '..' || $file == '.') {
                continue;
            }

            if (is_dir($path . $file)) {
                if (($fuuid = $this->create_dir($file, $uuid)) === false) {
                    return false;
                }

                if ($recurse) {
                    if (!$this->upload_dir($path . $file, $fuuid)) {
                        return false;
                    }
                }
            } else if (is_file($path . $file)) {
                if (!elis_files_upload_file('', $path . $file, $uuid)) {
                    return false;
                }
            }
        }

        if (ELIS_FILES_DEBUG_TIME) {
            $end  = microtime(true);
            $time = $end - $start;
            mtrace("upload_dir('$path', '$uuid', $recurse): $time");
        }

        return true;
    }
Exemple #5
0
    /**
     * Save the file to the specified path
     * @return boolean TRUE on success
     */
    function save($path) {
        if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){
            return false;
        }

        // send temporary file to alfresco
        $result = elis_files_upload_file('',$path,$_GET['uuid']);

        // clean up temporary file
        if (file_exists($path)) {
            unlink($path);
        }

        return true;
    }
Exemple #6
0
 /**
  * This funciton uploads a file asserts some tests.
  * @param ELIS_files $repo an instance of ELIS_files
  * @param string $upload   The array index of the uploaded file.
  * @param string $path     The full path to the file on the local filesystem.
  * @param string $uuid     The UUID of the folder where the file is being uploaded to.
  * @return object Node values for the uploaded file.
  */
 protected function call_upload_file($repo, $upload, $path, $uuid) {
     $response = elis_files_upload_file($upload, $path, $uuid);
     if ($response && !empty($response->uuid)) {
         $this->createduuids[] = $response->uuid;
         $node = elis_files_get_parent($response->uuid);
         $this->assertTrue($node && !empty($node->uuid));
         $this->assertEquals($uuid, $node->uuid);
     }
     return $response;
 }