Commit 29556c4d authored by Robert Lyon's avatar Robert Lyon

Bug 1356638: Allow images to be embedded in static pages

So that they have artefact_file_embedded rows associated with them and
can display to non-admins

behatnotneeded

Change-Id: I477a910637ffc53e0e5be9ed44d0188f49b61bad
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 2c9d80bb
......@@ -73,10 +73,15 @@ $form = pieform(array(
function editsitepage_submit(Pieform $form, $values) {
$id = get_field('site_content', 'id', 'name', $values['pagename'], 'institution', 'mahara');
require_once('embeddedimage.php');
// Update the pagetext with any embedded image info
$pagetext = EmbeddedImage::prepare_embedded_images($values['pagetext'], 'staticpages', $id);
global $USER;
$data = new StdClass;
$data->name = $values['pagename'];
$data->content = $values['pagetext'];
$data->content = $pagetext;
$data->mtime = db_format_timestamp(time());
$data->mauthor = $USER->get('id');
$data->institution = 'mahara';
......
......@@ -115,7 +115,11 @@ function editsitepage_submit(Pieform $form, $values) {
$data = new StdClass;
$data->name = $values['pagename'];
if (empty($values['pageusedefault'])) {
$data->content = $values['pagetext'];
$id = get_field('site_content', 'id', 'name', $values['pagename'], 'institution', $values['pageinstitution']);
require_once('embeddedimage.php');
// Update the pagetext with any embedded image info
$pagetext = EmbeddedImage::prepare_embedded_images($values['pagetext'], 'staticpages', $id);
$data->content = $pagetext;
}
$data->mtime = db_format_timestamp(time());
$data->mauthor = $USER->get('id');
......
......@@ -185,7 +185,7 @@ function check_is_embedded_image_visible($fileid, $includeresourcetypes = null,
$isvisible = false;
// Check for resource types a file may be embeded in.
$resourcetypes = array(
'comment', 'annotation', 'annotationfeedback', 'blog', 'textbox', 'editnote', 'text', 'introtext', 'wallpost'
'comment', 'annotation', 'annotationfeedback', 'blog', 'textbox', 'editnote', 'text', 'introtext', 'wallpost', 'staticpages'
);
if (!empty($includeresourcetypes)) {
if (!is_array($includeresourcetypes)) {
......
......@@ -1218,6 +1218,11 @@ class User {
* @return boolean
*/
public function can_publish_artefact($a) {
if (defined('INSTALLER')) {
// we are inside an install/upgrade so should mimic admin user
return true;
}
$parent = $a->get_parent_instance();
if ($parent) {
if (!$this->can_view_artefact($parent)) {
......
......@@ -996,6 +996,7 @@
</TABLE>
<TABLE NAME="site_content">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="content" TYPE="text" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
......@@ -1004,10 +1005,13 @@
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name,institution" />
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="mauthorfk" TYPE="foreign" FIELDS="mauthor" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name"/>
</KEYS>
<INDEXES>
<INDEX NAME="nameinstuk" UNIQUE="true" FIELDS="name,institution" />
</INDEXES>
</TABLE>
<!-- watchlist stuff -->
<TABLE NAME="usr_watchlist_view">
......
......@@ -5326,5 +5326,79 @@ function xmldb_core_upgrade($oldversion=0) {
clear_all_caches(true);
}
if ($oldversion < 2017092600) {
log_debug('Add primary key to site_content table');
// See if we need to add the id column
$table = new XMLDBTable('site_content');
$field = new XMLDBField('id');
if (!field_exists($table, $field)) {
log_debug('Making a temp copy and adding id column');
execute_sql('CREATE TEMPORARY TABLE {temp_site_content} AS SELECT DISTINCT * FROM {site_content}', array());
execute_sql('TRUNCATE {site_content}', array());
// Drop the current primary key as we will move it to the id column
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('name', 'institution'));
drop_key($table, $key);
if (is_mysql()) {
// MySQL requires the auto-increment column to be a primary key right away.
execute_sql('ALTER TABLE {site_content} ADD id BIGINT(10) NOT NULL auto_increment PRIMARY KEY FIRST');
}
else {
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
add_field($table, $field);
}
log_debug('Adding back in the site_content information');
// We will do in chuncks for large sites.
$count = 0;
$x = 0;
$limit = 1000;
$total = count_records('temp_site_content');
for ($i = 0; $i <= $total; $i += $limit) {
if (is_postgres()) {
$limitsql = ' OFFSET ' . $i . ' LIMIT ' . $limit;
}
else {
$limitsql = ' LIMIT ' . $i . ',' . $limit;
}
execute_sql('INSERT INTO {site_content} (name, content, ctime, mtime, mauthor, institution) SELECT name, content, ctime, mtime, mauthor, institution FROM {temp_site_content}' . $limitsql, array());
$count += $limit;
if (($count % ($limit *10)) == 0 || $count >= $total) {
if ($count > $total) {
$count = $total;
}
log_debug("$count/$total");
set_time_limit(30);
}
set_time_limit(30);
}
execute_sql('DROP TABLE {temp_site_content}', array());
if (!is_mysql()) {
log_debug('Adding primary key index to site_content.id column');
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
add_key($table, $key);
}
// Add the old key as new unique index
$index = new XMLDBIndex('nameinstuk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'institution'));
add_index($table, $index);
}
if ($results = get_records_sql_array("SELECT id, content FROM {site_content} WHERE content LIKE '%<img%'")) {
log_debug('Make sure images in static pages are embedded images');
require_once('embeddedimage.php');
foreach ($results as $result) {
// Update the page text with any embedded image info
$result->content = EmbeddedImage::prepare_embedded_images($result->content, 'staticpages', $result->id);
update_record('site_content', $result, array('id'));
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017092500;
$config->version = 2017092600;
$config->series = '17.10';
$config->release = '17.10dev';
$config->minupgradefrom = 2015030409;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment