/**
  * @desc Test creation of a derivation directory
  */
 function test_create_derivation_directory()
 {
     webwork_make_derivation_dir('SIMPLETEST', 'SIMPLETEST');
     $path = webwork_get_derivation_path_full('SIMPLETEST', 'SIMPLETEST');
     $this->assertEqual(is_dir($path), true, 'Webwork Derivation Directory Test.');
     webwork_delete_derivation_dir('SIMPLETEST', 'SIMPLETEST');
 }
Beispiel #2
0
 /**
  * @desc Updates the derivations of a wwquestion.
  * @param integer $wwquestionid The derivation to update.
  * @return boolean true
  */
 function _update_derivations($wwquestionid)
 {
     global $CFG;
     //retrieve the new records
     $newrecordset = webwork_qtype::_derivations();
     //retrieve the old records
     $oldrecordset = get_records('question_webwork_derived', 'question_webwork', $wwquestionid);
     //records that we will have
     $therecordset = array();
     //load in the new ones (by seed)
     foreach ($newrecordset as $newrecord) {
         unset($temprecord);
         //assign parentid
         $temprecord->question_webwork = $wwquestionid;
         //copy data
         $temprecord->seed = $newrecord['seed'];
         $temprecord->html = $newrecord['output'];
         $therecordset[$temprecord->seed] = $temprecord;
     }
     //overwrite IDs with old IDs if seeds match
     if (isset($oldrecordset)) {
         //stuff that exists and might be updatable
         foreach ($oldrecordset as $oldrecord) {
             //do we have an old seed that matches new seeds
             $oldseed = $oldrecord->seed;
             if (isset($therecordset[$oldseed]) && $therecordset[$oldseed] != null) {
                 //found a seed that already exists, make sure it goes into the old ID
                 $therecordset[$oldseed]->id = $oldrecord->id;
             } else {
                 //didnt find a seed that exists, delete the old record
                 $derivationid = $oldrecord->id;
                 webwork_delete_derivation_db($derivationid);
                 webwork_delete_derivation_dir($wwquestionid, $derivationid);
             }
         }
     }
     //update or insert into database
     foreach ($therecordset as $record) {
         //initial insert to get the ID when necessary
         if (!isset($record->id)) {
             unset($record->id);
             $result = insert_record('question_webwork_derived', $record);
             if (!$result) {
                 print_error('DB opertaion failed');
             }
             $record->id = $result;
         }
         //makes the derivation directory
         webwork_make_derivation_dir($wwquestionid, $record->id);
         webwork_parse_change_derivation($record);
         //updates record
         $err = update_record('question_webwork_derived', $record);
         if (!$err) {
             print_error('DB error on updating question_webwork_derived');
         }
     }
     return true;
 }