You are here

function filedepottest_createfolder in filedepot 6

1 call to filedepottest_createfolder()
filedepot_createtestrecords in ./lib-test.php

File

./lib-test.php, line 68
lib-test.php Test code that will only be used to create test folders and files for load testing

Code

function filedepottest_createfolder($pid, $foldername = '') {
  global $user, $_foldersCreated;
  $filedepot = filedepot_filedepot();
  $node = (object) array(
    'uid' => $user->uid,
    'name' => $user->name,
    'type' => 'filedepot_folder',
    'title' => "folder - pid{$pid}",
    'parentfolder' => $pid,
    'folderdesc' => '',
    'inherit' => 1,
  );
  node_save($node);
  $newcid = $filedepot->cid;
  $_foldersCreated[$newcid] = 0;

  // Track the number of files created in this folder
  if (empty($foldername)) {
    $foldername = "folder({$newcid}) - pid{$pid}";
  }
  db_query("UPDATE {filedepot_categories} SET name = '%s' where cid=%d", $foldername, $newcid);
  $filedepot
    ->updatePerms($newcid, $filedepot->defOwnerRights, $user->uid);
  if (isset($filedepot->defRoleRights) and count($filedepot->defRoleRights) > 0) {
    foreach ($filedepot->defRoleRights as $role => $perms) {
      $rid = db_result(db_query("SELECT rid FROM {role} WHERE name='%s'", $role));
      if ($rid and $rid > 0) {
        $filedepot
          ->updatePerms($newcid, $perms, '', array(
          $rid,
        ));
      }
    }
  }
  return $newcid;
}