Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
abbdfc3f
Commit
abbdfc3f
authored
Feb 12, 2015
by
Robert Lyon
Committed by
Gerrit Code Review
Feb 12, 2015
Browse files
Merge "(Bug 1364687) Don't look for an artefact record when we know we're making a new one."
parents
b95ca2e5
f0fd10e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/internal/lib.php
View file @
abbdfc3f
...
...
@@ -398,15 +398,17 @@ class ArtefactTypeProfile extends ArtefactType {
/**
* overriding this because profile fields
* are unique in that except for email, you only get ONE
* so if we don't get an id, we still need to go look for it
* so if we don't get an id, we still need to go look for it.
* On the other hand, if our caller knows the artefact is new,
* we can skip the query.
*/
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
public
function
__construct
(
$id
=
0
,
$data
=
null
,
$new
=
FALSE
)
{
$type
=
$this
->
get_artefact_type
();
if
(
!
empty
(
$id
)
||
$type
==
'email'
||
$type
==
'socialprofile'
)
{
return
parent
::
__construct
(
$id
,
$data
);
}
if
(
!
empty
(
$data
[
'owner'
]))
{
if
(
$a
=
get_record
(
'artefact'
,
'artefacttype'
,
$type
,
'owner'
,
$data
[
'owner'
]))
{
if
(
!
$new
&&
$a
=
get_record
(
'artefact'
,
'artefacttype'
,
$type
,
'owner'
,
$data
[
'owner'
]))
{
return
parent
::
__construct
(
$a
->
id
,
$a
);
}
else
{
...
...
htdocs/artefact/lib.php
View file @
abbdfc3f
...
...
@@ -257,10 +257,15 @@ abstract class ArtefactType implements IArtefactType {
* If an id is supplied, will query the database
* to build up the basic information about the object.
* If an id is not supplied, we just create an empty
* artefact, ready to be filled up
* @param int $id artefact.id
* artefact, ready to be filled up.
* If the $new parameter is true, we can skip the query
* because we know the artefact is new.
*
* @param int $id artefact.id
* @param mixed $data optional data supplied for artefact
* @param bool $new
*/
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
public
function
__construct
(
$id
=
0
,
$data
=
null
,
$new
=
FALSE
)
{
if
(
!
empty
(
$id
))
{
if
(
empty
(
$data
))
{
if
(
!
$data
=
get_record
(
'artefact'
,
'id'
,
$id
))
{
...
...
htdocs/lib/user.php
View file @
abbdfc3f
...
...
@@ -500,18 +500,24 @@ function plugin_account_prefs_submit(Pieform $form, $values) {
* @param int $userid
* @param string $field
* @param string (or array for socialprofile) $value
* @param int $new - Whether the user is new (avoid unnecessary queries)
*/
function
set_profile_field
(
$userid
,
$field
,
$value
)
{
function
set_profile_field
(
$userid
,
$field
,
$value
,
$new
=
FALSE
)
{
safe_require
(
'artefact'
,
'internal'
);
// this is a special case that replaces the primary email address with the
// specified one
if
(
$field
==
'email'
)
{
try
{
$email
=
artefact_instance_from_type
(
'email'
,
$userid
);
if
(
!
$new
)
{
try
{
$email
=
artefact_instance_from_type
(
'email'
,
$userid
);
}
catch
(
ArtefactNotFoundException
$e
)
{
// We'll create a new artefact then.
}
}
catch
(
ArtefactNotFoundException
$e
)
{
$email
=
new
ArtefactTypeEmail
();
if
(
!
isset
(
$email
)
)
{
$email
=
new
ArtefactTypeEmail
(
0
,
null
,
TRUE
);
$email
->
set
(
'owner'
,
$userid
);
}
$email
->
set
(
'title'
,
$value
);
...
...
@@ -519,7 +525,7 @@ function set_profile_field($userid, $field, $value) {
}
else
if
(
$field
==
'socialprofile'
)
{
$classname
=
generate_artefact_class_name
(
$field
);
$profile
=
new
$classname
(
0
,
array
(
'owner'
=>
$userid
));
$profile
=
new
$classname
(
0
,
array
(
'owner'
=>
$userid
)
,
$new
);
$profile
->
set
(
'title'
,
$value
[
'socialprofile_profileurl'
]);
$profile
->
set
(
'description'
,
$value
[
'socialprofile_service'
]);
$profile
->
set
(
'note'
,
$value
[
'socialprofile_profiletype'
]);
...
...
@@ -527,7 +533,7 @@ function set_profile_field($userid, $field, $value) {
}
else
{
$classname
=
generate_artefact_class_name
(
$field
);
$profile
=
new
$classname
(
0
,
array
(
'owner'
=>
$userid
));
$profile
=
new
$classname
(
0
,
array
(
'owner'
=>
$userid
)
,
$new
);
$profile
->
set
(
'title'
,
$value
);
$profile
->
commit
();
}
...
...
@@ -2281,19 +2287,19 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
}
if
(
isset
(
$user
->
email
)
&&
$user
->
email
!=
''
)
{
set_profile_field
(
$user
->
id
,
'email'
,
$user
->
email
);
set_profile_field
(
$user
->
id
,
'email'
,
$user
->
email
,
TRUE
);
}
if
(
isset
(
$user
->
firstname
)
&&
$user
->
firstname
!=
''
)
{
set_profile_field
(
$user
->
id
,
'firstname'
,
$user
->
firstname
);
set_profile_field
(
$user
->
id
,
'firstname'
,
$user
->
firstname
,
TRUE
);
}
if
(
isset
(
$user
->
lastname
)
&&
$user
->
lastname
!=
''
)
{
set_profile_field
(
$user
->
id
,
'lastname'
,
$user
->
lastname
);
set_profile_field
(
$user
->
id
,
'lastname'
,
$user
->
lastname
,
TRUE
);
}
foreach
(
$profile
as
$k
=>
$v
)
{
if
(
in_array
(
$k
,
array
(
'firstname'
,
'lastname'
,
'email'
)))
{
continue
;
}
set_profile_field
(
$user
->
id
,
$k
,
$v
);
set_profile_field
(
$user
->
id
,
$k
,
$v
,
TRUE
);
}
if
(
!
empty
(
$institution
))
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment