public function testCreateSubClassOf()
 {
     $this->hardify();
     $this->createData();
     $classProxy = ClassProxy::singleton();
     // Any new subclass of an hardified class must be hardified as well.
     $this->targetSongClass = $this->targetWorkClass->createSubClass('Song', 'The Song Class');
     $this->assertTrue($this->targetSongClass->exists());
     $this->assertIsA($classProxy->getImpToDelegateTo($this->targetSongClass), 'oat\\generisHard\\models\\hardsql\\Clazz');
 }
 /**
  * Call to launch export method of exporter
  *
  * php index.php 'oat\taoQtiItem\model\flyExporter\ExporterAction' $uri
  *
  * @param $params $params[0] is optional uri parameter
  * @return \common_report_Report
  */
 public function __invoke($params)
 {
     try {
         \common_ext_ExtensionsManager::singleton()->getExtensionById('taoItems');
         $exporterService = $this->getServiceManager()->get(SimpleExporter::SERVICE_ID);
         $uri = isset($params[0]) ? $params[0] : null;
         if (!is_null($uri)) {
             $class = new \core_kernel_classes_Class($uri);
             if ($class->exists()) {
                 $items = $class->getInstances(true);
             } else {
                 throw new \Exception("Exporter needs a valid class uri.");
             }
         }
         $filename = $exporterService->export(isset($items) ? $items : $uri);
         return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, "\nExport end.\nCSV export is located at: " . $filename . "\n");
     } catch (\Exception $e) {
         \common_Logger::w('Error during item metadata export: ' . $e->getMessage());
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, "\n" . $e->getMessage() . "\n");
     }
 }
示例#3
0
 public function testClearRoles()
 {
     $prefix = LOCAL_NAMESPACE . '#';
     $roleUris = array($prefix . 'baseRole', $prefix . 'subRole1', $prefix . 'subRole2', $prefix . 'subRole3', $prefix . 'subRole11', $prefix . 'subRole12', $prefix . 'subRole13');
     foreach ($roleUris as $ru) {
         $r = new core_kernel_classes_Class($ru);
         $r->delete(true);
         $this->assertFalse($r->exists());
     }
 }
 /**
  * @depends testAdd
  */
 public function testDelete($returnedLink)
 {
     $this->fileManagerMock->expects($this->once())->method('deleteFile')->with('myGreatLink')->willReturn(true);
     $instance = new \core_kernel_classes_Resource($returnedLink);
     $this->assertInstanceOf('\\core_kernel_classes_Resource', $instance, 'This class should exists');
     $success = $this->mediaManagerManagement->delete($returnedLink);
     // should return true
     $this->assertTrue($success, 'The file is not deleted');
     // should remove the instance
     $removedInstance = new \core_kernel_classes_Class($instance->getUri());
     $this->assertFalse($instance->exists(), 'The instance still exists');
     $this->assertFalse($removedInstance->exists(), 'The instance still exists');
 }
 /**
  * 
  * @param string $path
  * @return \core_kernel_classes_Class
  */
 private function getOrCreatePath($path)
 {
     if ($path === '') {
         $clazz = $this->getRootClass();
     } else {
         $clazz = new \core_kernel_classes_Class(\tao_helpers_uri::decode($path));
         if (!$clazz->isSubClassOf($this->getRootClass()) && !$clazz->equals($this->getRootClass()) && !$clazz->exists()) {
             // consider $path to be a label
             $found = false;
             foreach ($this->getRootClass()->getSubClasses() as $subclass) {
                 if ($subclass->getLabel() === $path) {
                     $found = true;
                     $clazz = $subclass;
                     break;
                 }
             }
             if (!$found) {
                 $clazz = $this->getRootClass()->createSubClass($path);
             }
         }
     }
     return $clazz;
 }
 public function testCreateUnits()
 {
     set_time_limit(300);
     $this->itemClass = null;
     $this->units = array();
     $this->properties = array();
     $this->files = array();
     $classUri = LOCAL_NAMESPACE . '#TranslationItemsClass';
     $translationClass = new core_kernel_classes_Class($classUri);
     if (!$translationClass->exists()) {
         $itemClass = new core_kernel_classes_Class(TAO_ITEM_CLASS);
         $translationClass = $itemClass->createSubClass('Translation Items', 'created for translation process execution test case', $classUri);
         $this->assertIsA($translationClass, 'core_kernel_classes_Class');
     }
     $this->itemClass = $translationClass;
     foreach ($this->unitNames as $unitName) {
         //create unit:
         $this->units[$unitName] = $translationClass->createInstance($unitName, 'created for translation process execution test case');
         $this->assertNotNull($this->units[$unitName]);
     }
     //		var_dump($this->units, $this->properties, $this->files);
 }
示例#7
0
 /**
  * (non-PHPdoc)
  * @see core_kernel_persistence_ClassInterface::deleteInstances()
  */
 public function deleteInstances(core_kernel_classes_Class $resource, $resources, $deleteReference = false)
 {
     $returnValue = false;
     $class = new core_kernel_classes_Class($resource->getUri());
     $uris = array();
     foreach ($resources as $r) {
         $uri = $r instanceof core_kernel_classes_Resource ? $r->getUri() : $r;
         $uris[] = $this->getPersistence()->quote($uri);
     }
     if ($class->exists()) {
         $inValues = implode(',', $uris);
         $query = 'DELETE FROM statements WHERE subject IN (' . $inValues . ')';
         if (true === $deleteReference) {
             $params[] = $resource->getUri();
             $query .= ' OR object IN (' . $inValues . ')';
         }
         try {
             // Even if now rows are affected, we consider the resources
             // as deleted.
             $this->getPersistence()->exec($query);
             $returnValue = true;
         } catch (PDOException $e) {
             throw new core_kernel_persistence_smoothsql_Exception("An error occured while deleting resources: " . $e->getMessage());
         }
     }
     return $returnValue;
 }