本文整理汇总了PHP中ensure_record_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP ensure_record_exists函数的具体用法?PHP ensure_record_exists怎么用?PHP ensure_record_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensure_record_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_blocktype_externalvideo_upgrade
function xmldb_blocktype_externalvideo_upgrade($oldversion = 0)
{
if ($oldversion < 2014030500) {
$urlpattern = '#\\b(https?://)prezi\\.com/bin/preziloader\\.swf\\?prezi_id=([a-z0-9]+)\\b#';
$matches = array();
$sql = "SELECT id, configdata FROM {block_instance} WHERE blocktype='externalvideo'";
$records = get_records_sql_array($sql, array());
if ($records) {
foreach ($records as $r) {
$configdata = unserialize($r->configdata);
if (isset($configdata['html'])) {
preg_match($urlpattern, $configdata['html'], $matches);
} else {
if (isset($configdata['videoid'])) {
preg_match($urlpattern, $configdata['videoid'], $matches);
}
}
if (count($matches) >= 3) {
$newurl = $matches[1] . 'prezi.com/embed/' . $matches[2];
$width = !empty($configdata['width']) ? $configdata['width'] : 0;
$height = !empty($configdata['height']) ? $configdata['height'] : 0;
$configdata['html'] = $configdata['videoid'] = PluginBlocktypeExternalvideo::iframe_code($newurl, $width, $height);
set_field('block_instance', 'configdata', serialize($configdata), 'id', $r->id);
}
}
}
ensure_record_exists('iframe_source_icon', (object) array('name' => 'Prezi', 'domain' => 'prezi.com'), (object) array('name' => 'Prezi', 'domain' => 'prezi.com'));
ensure_record_exists('iframe_source', (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'), (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'));
update_safe_iframe_regex();
}
return true;
}
示例2: postinst
public static function postinst($prevversion)
{
// Add blocktype category called 'survey' if it doesn't exists...
ensure_record_exists('blocktype_category', (object) array('name' => 'survey'), (object) array('name' => 'survey'));
if ($prevversion == 0) {
// 1. Convert MyLearning artefacts to Survey artefacts (mhr_artefact table)...
convert_artefacts_to_survey('multipleintelligences');
convert_artefacts_to_survey('learningstyles');
// 2. Install survey artefact blocktype named survey and later correctly convert block instances used in views...
install_survey_blocktype();
// 3. Convert block instances used in views (mhr_block_instance table)...
convert_blocks_used_in_views('multipleintelligences');
convert_blocks_used_in_views('learningstyles');
// 4. Delete multipleintelligences and learningstyles blocks from mhr_blocktype_installed* tables...
delete_records('blocktype_installed_viewtype', 'blocktype', 'multipleintelligences');
delete_records('blocktype_installed_category', 'blocktype', 'multipleintelligences');
delete_records('blocktype_installed_viewtype', 'blocktype', 'learningstyles');
delete_records('blocktype_installed_category', 'blocktype', 'learningstyles');
delete_records('blocktype_installed', 'artefactplugin', 'learning');
// 5. Delete learning artefact from mhr_artefact_installed* tables...
delete_records('artefact_installed_type', 'plugin', 'learning');
delete_records('artefact_installed', 'name', 'learning');
// 6. Recursive delete learning folder from htdocs/artefact/learning...
recursive_folder_delete(get_config('docroot') . 'artefact/learning/');
}
}
示例3: xmldb_interaction_forum_upgrade
function xmldb_interaction_forum_upgrade($oldversion = 0)
{
if ($oldversion < 2009062300) {
foreach (array('topic', 'forum') as $type) {
log_debug("Subscription upgrade for {$type}s");
// Add missing primary key to the subscription tables
// Step 1: remove duplicates
if ($dupes = get_records_sql_array('
SELECT "user", ' . $type . ', COUNT(*)
FROM {interaction_forum_subscription_' . $type . '}
GROUP BY "user", ' . $type . '
HAVING COUNT(*) > 1', array())) {
// We found duplicate subscriptions to a topic/forum
foreach ($dupes as $dupe) {
log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}");
delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type});
insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type}));
}
}
// Step 2: add the actual key
$table = new XMLDBTable('interaction_forum_subscription_' . $type);
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type));
add_key($table, $key);
// Add a 'key' column, used for unsubscriptions
$field = new XMLDBField('key');
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null);
add_field($table, $field);
$key = new XMLDBKey('keyuk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('key'));
add_key($table, $key);
// Populate the key column
if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) {
foreach ($records as $where) {
$new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand()));
update_record('interaction_forum_subscription_' . $type, $new, $where);
}
}
// Now make the key column not null
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
change_field_notnull($table, $field);
}
}
if ($oldversion < 2009081700) {
if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) {
insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30));
}
}
if ($oldversion < 2009081800) {
$subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum');
ensure_record_exists('interaction_event_subscription', $subscription, $subscription);
}
return true;
}
示例4: submitview_submit
function submitview_submit(Pieform $form, $values)
{
global $SESSION, $USER, $viewid, $groupid, $group;
db_begin();
update_record('view', array('submittedgroup' => $groupid, 'submittedtime' => db_format_timestamp(time())), array('id' => $viewid));
$roles = get_column('grouptype_roles', 'role', 'grouptype', $group->grouptype, 'see_submitted_views', 1);
foreach ($roles as $role) {
$accessrecord = (object) array('view' => $viewid, 'group' => $groupid, 'role' => $role, 'visible' => 0, 'allowcomments' => 1, 'approvecomments' => 0);
ensure_record_exists('view_access', $accessrecord, $accessrecord);
}
ArtefactType::update_locked($USER->get('id'));
activity_occurred('groupmessage', array('subject' => get_string('viewsubmitted', 'view'), 'message' => get_string('viewsubmitted', 'view'), 'submittedview' => $viewid, 'viewowner' => $USER->get('id'), 'group' => $groupid, 'roles' => $roles, 'strings' => (object) array('urltext' => (object) array('key' => 'view'))));
db_commit();
$SESSION->add_ok_msg(get_string('viewsubmitted', 'view'));
redirect('/' . returnto());
}
示例5: xmldb_artefact_blog_upgrade
function xmldb_artefact_blog_upgrade($oldversion = 0)
{
if ($oldversion < 2008101602) {
$table = new XMLDBTable('artefact_blog_blogpost_file_pending');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('oldextension', XMLDB_TYPE_TEXT, null);
$table->addFieldInfo('filetype', XMLDB_TYPE_TEXT, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
create_table($table);
}
if ($oldversion < 2009033100) {
$bloguploadbase = get_config('dataroot') . 'artefact/blog/uploads/';
if (is_dir($bloguploadbase)) {
if ($basedir = opendir($bloguploadbase)) {
while (false !== ($sessionupload = readdir($basedir))) {
if ($sessionupload != "." && $sessionupload != "..") {
$sessionupload = $bloguploadbase . $sessionupload;
$subdir = opendir($sessionupload);
while (false !== ($uploadfile = readdir($subdir))) {
if ($uploadfile != "." && $uploadfile != "..") {
$uploadfile = $sessionupload . '/' . $uploadfile;
unlink($uploadfile);
}
}
closedir($subdir);
rmdir($sessionupload);
}
}
}
@rmdir($bloguploadbase);
}
}
if ($oldversion < 2009081800) {
$subscription = (object) array('plugin' => 'blog', 'event' => 'createuser', 'callfunction' => 'create_default_blog');
ensure_record_exists('artefact_event_subscription', $subscription, $subscription);
}
if ($oldversion < 2011091400) {
delete_records('artefact_cron', 'plugin', 'blog', 'callfunction', 'clean_post_files');
}
if ($oldversion < 2015011500) {
delete_records('institution_config', 'field', 'progressbaritem_blog_blog');
}
return true;
}
示例6: editsitepage_submit
function editsitepage_submit(Pieform $form, $values)
{
global $USER;
$data = new StdClass();
$data->name = $values['pagename'];
if (empty($values['pageusedefault'])) {
$data->content = $values['pagetext'];
}
$data->mtime = db_format_timestamp(time());
$data->mauthor = $USER->get('id');
$data->institution = $values['pageinstitution'];
// update the institution config if needed
if (isset($values['pageusedefault'])) {
$configdata = new StdClass();
$configdata->institution = $data->institution;
$configdata->field = 'sitepages_' . $data->name;
$whereobj = clone $configdata;
$configdata->value = !empty($values['pageusedefault']) ? 'mahara' : $data->institution;
ensure_record_exists('institution_config', $whereobj, $configdata);
}
if (get_record('site_content', 'name', $data->name, 'institution', $data->institution)) {
try {
update_record('site_content', $data, array('name', 'institution'));
} catch (SQLException $e) {
$form->reply(PIEFORM_ERR, get_string('savefailed', 'admin'));
}
} else {
// local site page doesn't exist for this institution so we shall add it
$data->ctime = db_format_timestamp(time());
try {
insert_record('site_content', $data);
} catch (SQLException $e) {
$form->reply(PIEFORM_ERR, get_string('savefailed', 'admin'));
}
}
$form->reply(PIEFORM_OK, get_string('pagesaved', 'admin'));
}
示例7: commit
/**
* Overrides the default commit to make sure that any 'entireresume' blocks
* in views the user have know about this artefact - but only if necessary.
* Goals and skills are not in the entireresume block
*
* @param boolean $updateresumeblocks Whether to update any resume blockinstances
*/
public function commit()
{
parent::commit();
if ($blockinstances = get_records_sql_array('
SELECT id, "view", configdata
FROM {block_instance}
WHERE blocktype = \'entireresume\'
AND "view" IN (
SELECT id
FROM {view}
WHERE "owner" = ?)', array($this->owner))) {
foreach ($blockinstances as $blockinstance) {
$whereobject = (object) array('view' => $blockinstance->view, 'artefact' => $this->get('id'), 'block' => $blockinstance->id);
ensure_record_exists('view_artefact', $whereobject, $whereobject);
}
}
}
示例8: attach
public function attach($attachmentid)
{
if (record_exists('artefact_attachment', 'artefact', $this->get('id'), 'attachment', $attachmentid)) {
return;
}
if (!record_exists('artefact', 'id', $attachmentid)) {
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'mahara', $attachmentid));
}
$data = new StdClass();
$data->artefact = $this->get('id');
$data->attachment = $attachmentid;
insert_record('artefact_attachment', $data);
$data = new StdClass();
$data->artefact = $attachmentid;
$data->parent = $this->get('id');
$data->dirty = true;
insert_record('artefact_parent_cache', $data);
// Ensure the attachment is recorded as being related to the parent as well
if ($this->get('parent')) {
$data = new StdClass();
$data->artefact = $attachmentid;
$data->parent = $this->get('parent');
$data->dirty = 0;
$where = $data;
unset($where->dirty);
ensure_record_exists('artefact_parent_cache', $where, $data);
}
}
示例9: instance_config_save
public static function instance_config_save($values)
{
// we need to turn the feed url into an id in the feed_data table..
if (strpos($values['url'], '://') == false) {
// try add on http://
$values['url'] = 'http://' . $values['url'];
}
// We know this is safe because self::parse_feed caches its result and
// the validate method would have failed if the feed was invalid
$authpassword = !empty($values['authpassword']['submittedvalue']) ? $values['authpassword']['submittedvalue'] : (!empty($values['authpassword']['defaultvalue']) ? $values['authpassword']['defaultvalue'] : '');
$data = self::parse_feed($values['url'], $values['insecuresslmode'], $values['authuser'], $authpassword);
$data->content = serialize($data->content);
$data->image = serialize($data->image);
$data->lastupdate = db_format_timestamp(time());
$wheredata = array('url' => $values['url'], 'authuser' => $values['authuser'], 'authpassword' => $authpassword);
$id = ensure_record_exists('blocktype_externalfeed_data', $wheredata, $data, 'id', true);
$values['feedid'] = $id;
unset($values['url']);
return $values;
}
示例10: xmldb_interaction_forum_upgrade
function xmldb_interaction_forum_upgrade($oldversion = 0)
{
if ($oldversion < 2009062300) {
foreach (array('topic', 'forum') as $type) {
log_debug("Subscription upgrade for {$type}s");
// Add missing primary key to the subscription tables
// Step 1: remove duplicates
if ($dupes = get_records_sql_array('
SELECT "user", ' . $type . ', COUNT(*)
FROM {interaction_forum_subscription_' . $type . '}
GROUP BY "user", ' . $type . '
HAVING COUNT(*) > 1', array())) {
// We found duplicate subscriptions to a topic/forum
foreach ($dupes as $dupe) {
log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}");
delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type});
insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type}));
}
}
// Step 2: add the actual key
$table = new XMLDBTable('interaction_forum_subscription_' . $type);
$key = new XMLDBKey('primary');
$key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type));
add_key($table, $key);
// Add a 'key' column, used for unsubscriptions
$field = new XMLDBField('key');
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null);
add_field($table, $field);
$key = new XMLDBKey('keyuk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('key'));
add_key($table, $key);
// Populate the key column
if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) {
foreach ($records as $where) {
$new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand()));
update_record('interaction_forum_subscription_' . $type, $new, $where);
}
}
// Now make the key column not null
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
change_field_notnull($table, $field);
}
}
if ($oldversion < 2009081700) {
if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) {
insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30));
}
}
if ($oldversion < 2009081800) {
$subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum');
ensure_record_exists('interaction_event_subscription', $subscription, $subscription);
}
if ($oldversion < 2012071100) {
// Add new column 'path' to table interaction_forum_post used for diplaying posts by threads
$table = new XMLDBTable('interaction_forum_post');
$field = new XMLDBField('path');
$field->setAttributes(XMLDB_TYPE_CHAR, 2048, null, null);
add_field($table, $field);
$index = new XMLDBIndex('pathix');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('path'));
add_index($table, $index);
// Update the column 'path' for all posts in the old database
$done = 0;
$lastid = 0;
$pwcount = count_records('interaction_forum_post');
if (is_mysql()) {
$mp = mysql_get_variable('max_allowed_packet');
$limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100;
} else {
$limit = 2000;
}
while ($posts = get_records_select_array('interaction_forum_post', 'id > ?', array($lastid), 'id', 'id, parent', 0, $limit)) {
foreach ($posts as $post) {
// Update the column 'path'
$path = sprintf('%010d', $post->id);
$parentid = $post->parent;
while (!empty($parentid)) {
if ($p = get_record_select('interaction_forum_post', 'id = ?', array($parentid), 'parent, path')) {
if (!empty($p->path)) {
$path = $p->path . '/' . $path;
break;
}
$path = sprintf('%010d', $parentid) . '/' . $path;
$parentid = $p->parent;
} else {
throw new SQLException("Can't find the post with id = '{$parentid}'");
}
}
$post->path = $path;
update_record('interaction_forum_post', $post);
$lastid = $post->id;
}
$done += count($posts);
log_debug("Updating posts' path: {$done}/{$pwcount}");
set_time_limit(50);
}
}
if ($oldversion < 2014050800) {
// Subscribe admins to new activity.
$adminusers = get_column('usr', 'id', 'admin', 1, 'deleted', 0);
//.........这里部分代码省略.........
示例11: xmldb_artefact_europass_upgrade
function xmldb_artefact_europass_upgrade($oldversion = 0)
{
$status = true;
if ($oldversion < 2008012200) {
if (is_mysql()) {
$inttype = 'BIGINT(10)';
} else {
$inttype = 'INTEGER';
}
foreach (array('artefact_europass_mothertongue', 'artefact_europass_otherlanguage') as $table) {
$records = get_records_array($table, '', '', 'experiencestartdate DESC', 'id,experiencestartdate,experienceenddate,certificatedate');
// Sigh. table_column is screwed beyond belief. We let it do its
// work (in the case of start and stopdate at least because it does
// cast the columns OK), then fix its bugs
execute_sql('ALTER TABLE {' . $table . '} ADD displayorder ' . $inttype);
table_column($table, 'experiencestartdate', 'experiencestartdate', 'text', null, null, '', 'not null');
table_column($table, 'experienceenddate', 'experienceenddate', 'text', null, null, '', '');
table_column($table, 'certificatedate', 'certificatedate', 'text', null, null, '', '');
// MySQL docs say:
// * BLOB and TEXT columns cannot have DEFAULT values.
// It turns out they do - a default of ''. And dropping this results in:
// mysql> ALTER TABLE "artefact_resume_employmenthistory" ALTER COLUMN startdate DROP DEFAULT;
// ERROR 1101 (42000): BLOB/TEXT column 'startdate' can't have a default value
//
if (is_postgres()) {
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN experiencestartdate DROP DEFAULT');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN experienceenddate DROP DEFAULT');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN certificatedate DROP DEFAULT');
}
if (!empty($records)) {
foreach ($records as $k => $r) {
set_field($table, 'displayorder', $k, 'id', $r->id);
set_field($table, 'experiencestartdate', format_date(strtotime($r->startdate), 'strftimedate', 'current', 'artefact.europass'), 'id', $r->id);
set_field($table, 'experienceenddate', format_date(strtotime($r->enddate), 'strftimedate', 'current', 'artefact.europass'), 'id', $r->id);
set_field($table, 'certificatedate', format_date(strtotime($r->enddate), 'strftimedate', 'current', 'artefact.europass'), 'id', $r->id);
}
}
if (is_mysql()) {
execute_sql('ALTER TABLE {' . $table . '} MODIFY displayorder ' . $inttype . ' NOT NULL');
execute_sql('ALTER TABLE {' . $table . '} MODIFY experiencestartdate TEXT NOT NULL');
} else {
execute_sql('ALTER TABLE {' . $table . '} ALTER displayorder SET NOT NULL');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN experiencestartdate SET NOT NULL');
}
}
}
if ($oldversion < 2012051000) {
// Create 'artefact_europass_otherlanguage_diploma' table...
$table = new XMLDBTable('artefact_europass_languagediploma');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('languageid', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('certificate', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('awardingbody', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('certificatedate', XMLDB_TYPE_TEXT, null, null);
$table->addFieldInfo('europeanlevel', XMLDB_TYPE_CHAR, 2);
$table->addFieldInfo('displayorder', XMLDB_TYPE_INTEGER, 10, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
$table->addKeyInfo('languagefk', XMLDB_KEY_FOREIGN, array('languageid'), 'artefact_europass_otherlanguage', array('id'));
create_table($table);
// Create 'artefact_europass_otherlanguage_experience' table...
$table = new XMLDBTable('artefact_europass_languageexperience');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('languageid', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('startdate', XMLDB_TYPE_TEXT, null, null);
$table->addFieldInfo('enddate', XMLDB_TYPE_TEXT, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('displayorder', XMLDB_TYPE_INTEGER, 10, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
$table->addKeyInfo('languagefk', XMLDB_KEY_FOREIGN, array('languageid'), 'artefact_europass_otherlanguage', array('id'));
create_table($table);
// Install new artefact types (not previously installed!)
ensure_record_exists('artefact_installed_type', array('name' => 'languagediploma', 'plugin' => 'europass'), array('name' => 'languagediploma', 'plugin' => 'europass'));
ensure_record_exists('artefact_installed_type', array('name' => 'languageexperience', 'plugin' => 'europass'), array('name' => 'languageexperience', 'plugin' => 'europass'));
// Write values from 'artefact_europass_otherlanguage' to 'artefact_europass_otherlanguage_diploma'...
// Write values from 'artefact_europass_otherlanguage' to 'artefact_europass_otherlanguage_experience'...
$sql = "SELECT * FROM {artefact_europass_otherlanguage} l";
if ($records = get_records_sql_array($sql, array())) {
foreach ($records as $r) {
$owner = get_field('artefact', 'owner', 'id', $r->artefact);
$artefact = get_field('artefact', 'id', 'artefacttype', 'languagediploma', 'owner', $owner);
if (empty($r->certificate) && empty($r->awardingbody) && empty($r->certificatedate) && empty($r->europeanlevel)) {
// Do nothing...
} else {
if ($artefact == false) {
$time = time();
$insert = new StdClass();
$insert->artefacttype = 'languagediploma';
$insert->owner = $owner;
$insert->author = $owner;
$insert->ctime = db_format_timestamp($time);
$insert->mtime = db_format_timestamp($time);
$insert->atime = db_format_timestamp($time);
$insert->title = get_string('languagediploma', 'artefact.europass');
$artefact = insert_record('artefact', $insert, false, true);
}
$diploma = new StdClass();
//.........这里部分代码省略.........
示例12: install_watchlist_notification
function install_watchlist_notification()
{
if (!record_exists('config', 'field', 'watchlistnotification_delay')) {
set_config('watchlistnotification_delay', 20);
}
if (!table_exists(new XMLDBTable('watchlist_queue'))) {
$table = new XMLDBTable('watchlist_queue');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('usr', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('block', XMLDB_TYPE_INTEGER, 10, null, false);
$table->addFieldInfo('view', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('changed_on', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addKeyInfo('viewfk', XMLDB_KEY_FOREIGN, array('view'), 'view', array('id'));
$table->addKeyInfo('blockfk', XMLDB_KEY_FOREIGN, array('block'), 'block_instance', array('id'));
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
create_table($table);
}
// new event type: delete blockinstance
$e = new StdClass();
$e->name = 'deleteblockinstance';
ensure_record_exists('event_type', $e, $e);
// install the core event subscriptions
$subs = array(array('event' => 'blockinstancecommit', 'callfunction' => 'watchlist_record_changes'), array('event' => 'deleteblockinstance', 'callfunction' => 'watchlist_block_deleted'), array('event' => 'saveartefact', 'callfunction' => 'watchlist_record_changes'), array('event' => 'saveview', 'callfunction' => 'watchlist_record_changes'));
foreach ($subs as $sub) {
ensure_record_exists('event_subscription', (object) $sub, (object) $sub);
}
// install the cronjobs...
$cron = new StdClass();
$cron->callfunction = 'watchlist_process_notifications';
$cron->minute = '*';
$cron->hour = '*';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
ensure_record_exists('cron', $cron, $cron);
}
示例13: authenticate_user_account
/**
* Attempt to authenticate user
*
* @param string $user The user record to authenticate with
* @param string $password The password being used for authentication
* @return bool True/False based on whether the user
* authenticated successfully
* @throws AuthUnknownUserException If the user does not exist
*/
public function authenticate_user_account($user, $password)
{
$this->must_be_ready();
$username = $user->username;
// check ldap functionality exists
if (!function_exists('ldap_bind')) {
throw new AuthUnknownUserException('LDAP is not available in your PHP environment. Check that it is properly installed');
}
// empty username or password is not allowed.
if (empty($username) or empty($password)) {
return false;
}
// For update user info on login
$update = false;
if ('1' == $this->config['updateuserinfoonlogin']) {
$update = true;
}
// Missed out AD bit, someone might want to put it back :-)
// attempt ldap connection
$ldapconnection = $this->ldap_connect();
if ($ldapconnection) {
$ldap_user_dn = $this->ldap_find_userdn($ldapconnection, $username);
//if ldap_user_dn is empty, user does not exist
if (!$ldap_user_dn) {
$this->ldap_close($ldapconnection);
return false;
}
// Try to bind with current username and password
$ldap_login = @ldap_bind($ldapconnection, $ldap_user_dn, $password);
$this->ldap_close($ldapconnection);
if ($ldap_login) {
if ($user->id && $update) {
// Define ldap attributes
$ldapattributes = array();
$ldapattributes['firstname'] = $this->config['firstnamefield'];
$ldapattributes['lastname'] = $this->config['surnamefield'];
$ldapattributes['email'] = $this->config['emailfield'];
$ldapattributes['studentid'] = $this->config['studentidfield'];
$ldapattributes['preferredname'] = $this->config['preferrednamefield'];
// Retrieve information of user from LDAP
$ldapdetails = $this->get_userinfo_ldap($username, $ldapattributes);
// Match database and ldap entries and update in database if required
$fieldstoimport = array_keys($ldapattributes);
foreach ($fieldstoimport as $field) {
if (!isset($ldapdetails[$field])) {
continue;
}
$sanitizer = "sanitize_{$field}";
$ldapdetails[$field] = $sanitizer($ldapdetails[$field]);
if (!empty($ldapdetails[$field]) && $user->{$field} != $ldapdetails[$field]) {
$user->{$field} = $ldapdetails[$field];
set_profile_field($user->id, $field, $ldapdetails[$field]);
if ('studentid' == $field && 'mahara' != $this->institution) {
// studentid is specific for the institution, so store it there too.
$dataobject = array('usr' => $user->id, 'institution' => $this->institution, 'ctime' => db_format_timestamp(time()), 'studentid' => $user->studentid);
$whereobject = $dataobject;
unset($whereobject['ctime']);
unset($whereobject['studentid']);
ensure_record_exists('usr_institution', $whereobject, $dataobject);
unset($dataobject);
unset($whereobject);
}
}
}
}
return true;
}
} else {
$this->ldap_close($ldapconnection);
// let's do some logging too
log_warn("LDAP connection failed: " . $this->config['host_url'] . '/' . $this->config['contexts']);
throw new AuthInstanceException(get_string('cannotconnect', 'auth.ldap'));
}
return false;
// No match
}
示例14: xmldb_artefact_file_upgrade
//.........这里部分代码省略.........
if ($oldversion < 2012092400) {
$basepath = get_config('dataroot') . "artefact/file/originals/";
try {
check_dir_exists($basepath, true);
} catch (Exception $e) {
throw new SystemException("Failed to create " . $basepath);
}
$baseiter = new DirectoryIterator($basepath);
foreach ($baseiter as $dir) {
if ($dir->isDot()) {
continue;
}
$dirpath = $dir->getPath() . '/' . $dir->getFilename();
$fileiter = new DirectoryIterator($dirpath);
foreach ($fileiter as $file) {
if ($file->isDot()) {
continue;
}
if (!$file->isFile()) {
log_error("Something was wrong about the dataroot in artefact/file/originals/{$dir}. Unexpected folder {$file}");
continue;
}
chmod($file->getPathname(), $file->getPerms() & 0666);
}
}
}
if ($oldversion < 2013031200) {
// Update MIME types for Microsoft video files: avi, asf, wm, and wmv
update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-asf', 'description' => 'asf'), (object) array('mimetype' => 'video/x-ms-asf'));
update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wm', 'description' => 'wm'), (object) array('mimetype' => 'video/x-ms-wm'));
update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wmv', 'description' => 'wmv'), (object) array('mimetype' => 'video/x-ms-wmv'));
}
if ($oldversion < 2014040800) {
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/aac'), (object) array('mimetype' => 'audio/aac', 'description' => 'aac'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/msaccess'), (object) array('mimetype' => 'application/msaccess', 'description' => 'accdb'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'shockwave/director'), (object) array('mimetype' => 'shockwave/director', 'description' => 'cct'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-csh'), (object) array('mimetype' => 'application/x-csh', 'description' => 'cs'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/css'), (object) array('mimetype' => 'text/css', 'description' => 'css'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/csv'), (object) array('mimetype' => 'text/csv', 'description' => 'csv'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/x-dv'), (object) array('mimetype' => 'video/x-dv', 'description' => 'dv'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'description' => 'docx'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12', 'description' => 'docm'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'description' => 'dotx'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12', 'description' => 'dotm'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-director'), (object) array('mimetype' => 'application/x-director', 'description' => 'dcr'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/epub+zip'), (object) array('mimetype' => 'application/epub+zip', 'description' => 'epub'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-smarttech-notebook'), (object) array('mimetype' => 'application/x-smarttech-notebook', 'description' => 'gallery'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/mac-binhex40'), (object) array('mimetype' => 'application/mac-binhex40', 'description' => 'hqx'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/x-component'), (object) array('mimetype' => 'text/x-component', 'description' => 'htc'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xhtml+xml'), (object) array('mimetype' => 'application/xhtml+xml', 'description' => 'xhtml'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/vnd.microsoft.icon'), (object) array('mimetype' => 'image/vnd.microsoft.icon', 'description' => 'ico'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/calendar'), (object) array('mimetype' => 'text/calendar', 'description' => 'ics'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration'), (object) array('mimetype' => 'application/inspiration', 'description' => 'isf'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration.template'), (object) array('mimetype' => 'application/inspiration.template', 'description' => 'ist'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/java-archive'), (object) array('mimetype' => 'application/java-archive', 'description' => 'jar'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-java-jnlp-file'), (object) array('mimetype' => 'application/x-java-jnlp-file', 'description' => 'jnlp'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.backup'), (object) array('mimetype' => 'application/vnd.moodle.backup', 'description' => 'mbz'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-msaccess'), (object) array('mimetype' => 'application/x-msaccess', 'description' => 'mdb'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'message/rfc822'), (object) array('mimetype' => 'message/rfc822', 'description' => 'mht'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.profiling'), (object) array('mimetype' => 'application/vnd.moodle.profiling', 'description' => 'mpr'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template', 'description' => 'otg'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template', 'description' => 'otp'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'description' => 'ots'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/ogg'), (object) array('mimetype' => 'audio/ogg', 'description' => 'oga'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/ogg'), (object) array('mimetype' => 'video/ogg', 'description' => 'ogv'));
ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/pict'), (object) array('mimetype' => 'image/pict', 'description' => 'pct'));
示例15: addfontform_submit
function addfontform_submit(Pieform $form, $values)
{
global $USER, $SESSION;
$foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, '', $values['fonttitle']);
// Assign a new name, if the font with the same name already exists...
$foldername = Skin::new_font_name($foldername);
$fontpath = get_config('dataroot') . 'skins/fonts/' . $foldername . '/';
check_dir_exists($fontpath, true, true);
// If we are uploading a zip file
if (!empty($values['fontfileZip'])) {
safe_require('artefact', 'file');
$zip = new ZipArchive();
if ($zip->open($values['fontfileZip']['tmp_name'])) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$fontname = dirname($zip->getNameIndex($i));
$filename = basename($zip->getNameIndex($i));
if (empty($fontname) || $fontname == '.') {
$fontname = substr($values['fontfileZip']['name'], 0, -1 * strlen('.zip'));
}
// Check that all the needed files exist in the zip file
$check = uploadfiles_info();
foreach ($check as $key => $item) {
if (end(explode('.', $zip->getNameIndex($i))) == $item['suffix']) {
// Extract font file
$zip->extractTo($fontpath, $zip->getNameIndex($i));
$values['fontfile' . strtoupper($item['suffix'])]['name'] = $zip->getNameIndex($i);
}
}
}
}
}
// Get SVG id from SVG font file...
$tempname = !empty($values['fontfileZip']) ? $fontpath . $values['fontfileSVG']['name'] : $values['fontfileSVG']['tmp_name'];
$filename = $values['fontfileSVG']['name'];
$xmlDoc = simplexml_load_string(file_get_contents($tempname));
$svg_id = (string) $xmlDoc->defs->font->attributes()->id;
// Insert new record with font data into 'skin_fonts' table in database...
// $foldername equals (only alphanumerical) font name, e.g. 'Nimbus Roman No.9' -> 'NimbusRomanNo9'
// $foldername is also used as primary key in 'skin_fonts' table.
switch ($values['fontstyle']) {
case 'regular':
$font_variant = 'regular';
$font_weight = 'normal';
$font_style = 'normal';
break;
case 'bold':
$font_variant = 'bold';
$font_weight = 'bold';
$font_style = 'normal';
break;
case 'italic':
$font_variant = 'italic';
$font_weight = 'normal';
$font_style = 'italic';
break;
case 'bolditalic':
$font_variant = 'bolditalic';
$font_weight = 'bold';
$font_style = 'italic';
break;
}
$variantdata = array('variant' => $font_variant, 'EOT' => $values['fontfileEOT']['name'], 'SVG' => $values['fontfileSVG']['name'], 'SVGid' => $svg_id, 'TTF' => $values['fontfileTTF']['name'], 'WOFF' => $values['fontfileWOFF']['name'], 'font-weight' => $font_weight, 'font-style' => $font_style);
// We'll create the database record before we copy the files over, so that
// Mahara will know about this font in order to be able to delete its contents
// from the filesystem if something goes wrong.
ensure_record_exists('skin_fonts', (object) array('name' => $foldername), (object) array('name' => $foldername, 'title' => $values['fonttitle'], 'licence' => $values['fontfilelicence']['name'], 'notice' => $values['fontnotice'], 'previewfont' => $values['fontfileTTF']['name'], 'variants' => serialize(array($font_variant => $variantdata)), 'fonttype' => 'site', 'onlyheading' => $values['fonttype'] == 'heading' ? 1 : 0, 'fontstack' => '\'' . escape_css_string($values['fonttitle']) . '\'', 'genericfont' => $values['genericfont']));
if (empty($values['fontfileZip'])) {
// Copy SVG font file to folder...
$tempname = $values['fontfileSVG']['tmp_name'];
$filename = $values['fontfileSVG']['name'];
move_uploaded_file($tempname, $fontpath . $filename);
// Copy EOT font file.
$tempname = $values['fontfileEOT']['tmp_name'];
$filename = $values['fontfileEOT']['name'];
move_uploaded_file($tempname, $fontpath . $filename);
// Copy TTF font file to folder...
$tempname = $values['fontfileTTF']['tmp_name'];
$filename = $values['fontfileTTF']['name'];
move_uploaded_file($tempname, $fontpath . $filename);
// Copy WOFF font file to folder...
$tempname = $values['fontfileWOFF']['tmp_name'];
$filename = $values['fontfileWOFF']['name'];
move_uploaded_file($tempname, $fontpath . $filename);
// Copy optional font licence file to folder, if it exists...
if (!empty($values['fontfilelicence'])) {
$tempname = $values['fontfilelicence']['tmp_name'];
$filename = $values['fontfilelicence']['name'];
move_uploaded_file($tempname, $fontpath . $filename);
}
}
$SESSION->add_ok_msg(get_string('fontinstalled', 'skin'));
redirect('/admin/site/fonts.php');
}