Ejemplo n.º 1
0
 /**
  * The content of this block is now stored as an html artefact, but older versions stored
  * the content directly in the 'text' property of the block config.  If this config has
  * 'text' but not 'artefactid', create an artefact.
  *
  * @param array $biconfig   The block instance config
  * @param array $viewconfig The view config
  * @return BlockInstance The newly made block instance
  */
 public static function import_create_blockinstance_leap(array $biconfig, array $viewconfig)
 {
     $configdata = $biconfig['config'];
     if (isset($configdata['text']) && !isset($configdata['artefactid'])) {
         $data = array('title' => $biconfig['title'], 'description' => $configdata['text'], 'license' => !empty($configdata['license']) ? $configdata['license'] : '', 'licensor' => !empty($configdata['licensor']) ? $configdata['licensor'] : '', 'licensorurl' => !empty($configdata['licensorurl']) ? $configdata['licensorurl'] : '', 'tags' => !empty($configdata['tags']) ? $configdata['tags'] : '', 'owner' => $viewconfig['owner']);
         $artefact = new ArtefactTypeHtml(0, $data);
         $artefact->commit();
         $configdata['artefactid'] = $artefact->get('id');
         unset($configdata['text']);
     }
     $bi = new BlockInstance(0, array('blocktype' => $biconfig['type'], 'configdata' => $configdata));
     return $bi;
 }
Ejemplo n.º 2
0
 public static function import_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     $artefactmapping = array();
     $entrydata = self::get_entry_data_using_strategy($entry, $importer, $strategy, $otherentries);
     if (!empty($entrydata)) {
         switch ($entrydata['type']) {
             case 'introduction':
                 $introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
                 $introduction->set('title', $entrydata['content']['title']);
                 $introduction->commit();
                 $artefactmapping[(string) $entry->id] = array($introduction->get('id'));
                 break;
             case 'html':
                 $note = new ArtefactTypeHtml();
                 $note->set('title', $entrydata['content']['title']);
                 $note->set('description', $entrydata['content']['description']);
                 $note->set('ctime', strtotime($entrydata['content']['ctime']));
                 $note->set('mtime', strtotime($entrydata['content']['mtime']));
                 $note->set('owner', $entrydata['owner']);
                 $note->commit();
                 $artefactmapping[(string) $entry->id] = array($note->get('id'));
                 // Check for note's attachments
                 if (isset($entry->link)) {
                     foreach ($entry->link as $link) {
                         if ($id = $importer->create_attachment($entry, $link, $note)) {
                             $artefactmapping[$link['href']][] = $id;
                         }
                     }
                     $note->commit();
                 }
                 break;
             default:
                 $artefactmapping[(string) $entry->id] = array(self::create_artefact($importer, $entrydata['type'], $entrydata['content']['title']));
                 break;
         }
     }
     return $artefactmapping;
 }
Ejemplo n.º 3
0
 /**
  * This function is meant to be run (either via the "convertnotes.php" CLI script,
  * or from the blocktype/text plugin config page) shortly after upgrading to
  * Mahara 1.10. It will locate all the existing Note blocks & their underlying Note
  * artefacts, and convert them into simple Text blocks if they are not using
  * any of the Note artefact's advanced features.
  *
  * @param integer $limit Limit the number of records processed to this many.
  * @return integer The number of notes converted
  */
 public static function convert_notes_to_text_blocks($limit = null)
 {
     $rs = self::find_convertible_text_blocks($limit);
     if (!$rs) {
         log_info("No old-style Text Box blocks to process.");
         return 0;
     }
     $total = $rs->NumRows();
     $countprocessed = 0;
     $countconverted = 0;
     log_info("Preparing to process {$total} old-style Text Box blocks.");
     while ($record = $rs->FetchRow()) {
         $countprocessed++;
         if ($countprocessed % 1000 == 0) {
             log_info("{$countprocessed}/{$total} processed...");
         }
         $record = (object) $record;
         $oldconfigdata = unserialize($record->configdata);
         // don't convert textboxes with tags, because the text doesn't support tags
         if (array_key_exists('tags', $oldconfigdata) && count($oldconfigdata['tags']) > 0) {
             continue;
         }
         // don't convert textboxes with a license, because the text
         // doesn't support licenses
         if (array_key_exists('license', $oldconfigdata) && strlen($oldconfigdata['license']) > 0) {
             continue;
         }
         // don't convert textboxes with connected artefacts, because the text
         // doesn't support additional artefacts
         if (array_key_exists('artefactids', $oldconfigdata) && count($oldconfigdata['artefactids']) > 0) {
             continue;
         }
         // ignore if the artefacttype returned is not 'html' - seems to exist if a text box has a download link in the markup
         if ($record->artefacttype != 'html') {
             continue;
         }
         db_begin();
         $record = (object) array('id' => $record->id, 'configdata' => $oldconfigdata, 'artefact' => $record->artefact);
         $htmlartefact = new ArtefactTypeHtml($record->artefact);
         $newconfigdata = array('text' => $htmlartefact->get('description'), 'retractable' => false, 'retractedonload' => false);
         if (array_key_exists('retractable', $record->configdata)) {
             $newconfigdata['retractable'] = $record->configdata['retractable'];
         }
         if (array_key_exists('retractedonload', $record->configdata)) {
             $newconfigdata['retractedonload'] = $record->configdata['retractedonload'];
         }
         $whereobj = (object) array('id' => $record->id);
         $newobj = (object) array('blocktype' => 'text', 'configdata' => serialize($newconfigdata));
         update_record('block_instance', $newobj, $whereobj);
         $htmlartefact->delete();
         $countconverted++;
         db_commit();
     }
     return $countconverted;
 }
Ejemplo n.º 4
0
 /**
  * Pieform success callback function for the config form. Converts the
  * text blocks, if the checkbox is ticked
  *
  * @param $form the pieform to send the ok-message to
  * @param array $values
  */
 public static function save_config_options($form, $values)
 {
     global $SESSION;
     if (!array_key_exists('convertcheckbox', $values) || !$values['convertcheckbox']) {
         return;
     }
     $records = self::find_convertible_text_blocks();
     $countconverted = 0;
     db_begin();
     foreach ($records as $record) {
         $htmlartefact = new ArtefactTypeHtml($record->artefact);
         $newconfigdata = array('text' => $htmlartefact->get('description'), 'retractable' => false, 'retractedonload' => false);
         if (array_key_exists('retractable', $record->configdata)) {
             $newconfigdata['retractable'] = $record->configdata['retractable'];
         }
         if (array_key_exists('retractedonload', $record->configdata)) {
             $newconfigdata['retractedonload'] = $record->configdata['retractedonload'];
         }
         $whereobj = (object) array('id' => $record->id);
         $newobj = (object) array('blocktype' => 'text', 'configdata' => serialize($newconfigdata));
         update_record('block_instance', $newobj, $whereobj);
         $htmlartefact->delete();
         $countconverted++;
     }
     db_commit();
     $form->json_reply(PIEFORM_OK, get_string('convertibleokmessage', 'blocktype.text', $countconverted));
 }