You are here

function filedepot_createtestrecords in filedepot 6

1 string reference to 'filedepot_createtestrecords'
filedepot_menu in ./filedepot.module
Implementation of hook_menu().

File

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

Code

function filedepot_createtestrecords() {
  global $parent_folders, $folders_created, $max_records_perfolder;
  global $_numfolders2create, $_numfiles2create, $_maxrecordsperfolder, $_validfolders;
  if (empty($_validfolders) or count($_validfolders) == 0) {
    $_validfolders[] = filedepottest_createfolder(0, 'Load Testing');
  }
  $folders_created = array();
  if ($_numfolders2create > 0) {
    for ($i = 1; $i <= $_numfolders2create; $i++) {
      $parent_folders = implode(',', $_validfolders);
      $pid = db_result(db_query_range("SELECT cid from {filedepot_categories} WHERE cid in ({$parent_folders}) ORDER BY RAND()", array(), 0, 1));
      $cnt = db_result(db_query("SELECT count(cid) FROM {filedepot_categories} WHERE cid=%d", $pid));
      if ($cnt != 1) {
        watchdog('filedepot', "create_testrecords abort, cid: @cid does not exist", array(
          '@cid' => $pid,
        ));
        echo "create_testrecords abort, cid: {$pid} does not exist";
        die;
      }
      $cid = filedepottest_createfolder($pid);
      $_validfolders[] = $cid;
    }
  }
  drupal_set_message(t('Created !numfolders new folders', array(
    '!numfolders' => $_numfolders2create,
  )), 'status');
  $parent_folders = implode(',', $_validfolders);
  for ($filenum = 1; $filenum <= $_numfiles2create; $filenum++) {

    // Select a random folder with less then max number of files
    $cid = filedepottest_selectRandomFolder();
    $sql = "INSERT INTO {filedepot_files} (cid,fname,title,version,description,mimetype,extension,submitter,status,date) ";
    $sql .= "VALUES (%d,'testfile.pdf','TestFile-%s','1','Phantom file created for stress testing','application/octet-stream','pdf',2,1,%d)";
    db_query($sql, $cid, $filenum, time());
    $lastrec = db_result(db_query_range("SELECT fid FROM {filedepot_files} ORDER BY fid DESC", array(), 0, 1));
    $sql = "INSERT INTO {filedepot_fileversions} (fid,fname,version,notes,date,uid,status) VALUES (%d,'%s','1','',%d,2,'1')";
    db_query($sql, $lastrec, 'testfile.pdf', time());
    $_foldersCreated[$cid]++;
  }
  drupal_set_message(t('Completed adding !numfiles new files', array(
    '!numfiles' => $filenum,
  )), 'status');
  drupal_goto();
}