Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
d5d652e2
Commit
d5d652e2
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
orm: Make the QuerySet stashable in the session
parent
8b6d2d1f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.orm.php
+57
-10
57 additions, 10 deletions
include/class.orm.php
with
57 additions
and
10 deletions
include/class.orm.php
+
57
−
10
View file @
d5d652e2
...
@@ -554,7 +554,7 @@ class Aggregate extends SqlFunction {
...
@@ -554,7 +554,7 @@ class Aggregate extends SqlFunction {
}
}
}
}
class
QuerySet
implements
IteratorAggregate
,
ArrayAccess
{
class
QuerySet
implements
IteratorAggregate
,
ArrayAccess
,
Serializable
{
var
$model
;
var
$model
;
var
$constraints
=
array
();
var
$constraints
=
array
();
...
@@ -776,19 +776,36 @@ class QuerySet implements IteratorAggregate, ArrayAccess {
...
@@ -776,19 +776,36 @@ class QuerySet implements IteratorAggregate, ArrayAccess {
// Load defaults from model
// Load defaults from model
$model
=
$this
->
model
;
$model
=
$this
->
model
;
if
(
!
$this
->
ordering
&&
isset
(
$model
::
$meta
[
'ordering'
]))
$query
=
clone
$this
;
$this
->
ordering
=
$model
::
$meta
[
'ordering'
];
if
(
!
$query
->
ordering
&&
isset
(
$model
::
$meta
[
'ordering'
]))
if
(
!
$this
->
related
&&
$model
::
$meta
[
'select_related'
])
$query
->
ordering
=
$model
::
$meta
[
'ordering'
];
$this
->
related
=
$model
::
$meta
[
'select_related'
];
if
(
!
$query
->
related
&&
$model
::
$meta
[
'select_related'
])
if
(
!
$this
->
defer
&&
$model
::
$meta
[
'defer'
])
$query
->
related
=
$model
::
$meta
[
'select_related'
];
$this
->
defer
=
$model
::
$meta
[
'defer'
];
if
(
!
$query
->
defer
&&
$model
::
$meta
[
'defer'
])
$query
->
defer
=
$model
::
$meta
[
'defer'
];
$class
=
$this
->
compiler
;
$class
=
$this
->
compiler
;
$compiler
=
new
$class
(
$options
);
$compiler
=
new
$class
(
$options
);
$this
->
query
=
$compiler
->
compileSelect
(
$
this
);
$this
->
query
=
$compiler
->
compileSelect
(
$
query
);
return
$this
->
query
;
return
$this
->
query
;
}
}
function
serialize
()
{
$info
=
get_object_vars
(
$this
);
unset
(
$info
[
'query'
]);
unset
(
$info
[
'limit'
]);
unset
(
$info
[
'offset'
]);
unset
(
$info
[
'_iterator'
]);
return
serialize
(
$info
);
}
function
unserialize
(
$data
)
{
$data
=
unserialize
(
$data
);
foreach
(
$data
as
$name
=>
$val
)
{
$this
->
{
$name
}
=
$val
;
}
}
}
}
class
DoesNotExist
extends
Exception
{}
class
DoesNotExist
extends
Exception
{}
...
@@ -1952,7 +1969,7 @@ class MysqlExecutor {
...
@@ -1952,7 +1969,7 @@ class MysqlExecutor {
}
}
}
}
class
Q
{
class
Q
implements
Serializable
{
const
NEGATED
=
0x0001
;
const
NEGATED
=
0x0001
;
const
ANY
=
0x0002
;
const
ANY
=
0x0002
;
...
@@ -1961,7 +1978,7 @@ class Q {
...
@@ -1961,7 +1978,7 @@ class Q {
var
$negated
=
false
;
var
$negated
=
false
;
var
$ored
=
false
;
var
$ored
=
false
;
function
__construct
(
$filter
,
$flags
=
0
)
{
function
__construct
(
$filter
=
array
()
,
$flags
=
0
)
{
if
(
!
is_array
(
$filter
))
if
(
!
is_array
(
$filter
))
$filter
=
array
(
$filter
);
$filter
=
array
(
$filter
);
$this
->
constraints
=
$filter
;
$this
->
constraints
=
$filter
;
...
@@ -1982,6 +1999,20 @@ class Q {
...
@@ -1982,6 +1999,20 @@ class Q {
return
$this
;
return
$this
;
}
}
function
union
()
{
$this
->
ored
=
true
;
}
function
add
(
$constraints
)
{
if
(
is_array
(
$constraints
))
$this
->
constraints
=
array_merge
(
$this
->
constraints
,
$constraints
);
elseif
(
$constraints
instanceof
static
)
$this
->
constraints
[]
=
$constraints
;
else
throw
new
InvalidArgumentException
(
'Expected an instance of Q or an array thereof'
);
return
$this
;
}
static
function
not
(
array
$constraints
)
{
static
function
not
(
array
$constraints
)
{
return
new
static
(
$constraints
,
self
::
NEGATED
);
return
new
static
(
$constraints
,
self
::
NEGATED
);
}
}
...
@@ -1989,5 +2020,21 @@ class Q {
...
@@ -1989,5 +2020,21 @@ class Q {
static
function
any
(
array
$constraints
)
{
static
function
any
(
array
$constraints
)
{
return
new
static
(
$constraints
,
self
::
ANY
);
return
new
static
(
$constraints
,
self
::
ANY
);
}
}
function
serialize
()
{
return
serialize
(
array
(
'f'
=>
(
$this
->
negated
?
self
::
NEGATED
:
0
)
|
(
$this
->
ored
?
self
::
ANY
:
0
),
'c'
=>
$this
->
constraints
));
}
function
unserialize
(
$data
)
{
$data
=
unserialize
(
$data
);
$this
->
constraints
=
$data
[
'c'
];
$this
->
ored
=
$data
[
'f'
]
&
self
::
ANY
;
$this
->
negated
=
$data
[
'f'
]
&
self
::
NEGATED
;
}
}
}
?>
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment