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
56a8f924
Commit
56a8f924
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Move upgrader from setup directory to scp
parent
03a84301
No related branches found
No related tags found
No related merge requests found
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scp/js/upgrader.js
+58
-0
58 additions, 0 deletions
scp/js/upgrader.js
scp/upgrade.php
+0
-0
0 additions, 0 deletions
scp/upgrade.php
setup/inc/class.attachment.migrate.php
+0
-162
0 additions, 162 deletions
setup/inc/class.attachment.migrate.php
with
58 additions
and
162 deletions
scp/js/upgrader.js
0 → 100644
+
58
−
0
View file @
56a8f924
jQuery
(
function
(
$
)
{
$
(
"
#overlay
"
).
css
({
opacity
:
0.3
,
top
:
0
,
left
:
0
,
width
:
$
(
window
).
width
(),
height
:
$
(
window
).
height
()
});
$
(
"
#loading
"
).
css
({
top
:
(
$
(
window
).
height
()
/
3
),
left
:
(
$
(
window
).
width
()
/
2
-
160
)
});
$
(
'
form#upgrade
'
).
submit
(
function
(
e
)
{
e
.
preventDefault
();
var
form
=
$
(
this
);
$
(
'
input[type=submit]
'
,
this
).
attr
(
'
disabled
'
,
'
disabled
'
);
$
(
'
#overlay, #loading
'
).
show
();
doTasks
(
'
upgrade.php
'
,
form
.
serialize
());
return
false
;
});
function
doTasks
(
url
,
data
)
{
function
_lp
(
count
)
{
$
.
ajax
({
type
:
'
POST
'
,
url
:
'
ajax.php/upgrader
'
,
async
:
true
,
cache
:
false
,
data
:
data
,
dataType
:
'
text
'
,
success
:
function
(
res
)
{
if
(
res
)
{
$
(
'
#loading #msg
'
).
html
(
res
);
}
},
statusCode
:
{
200
:
function
()
{
setTimeout
(
function
()
{
_lp
(
count
+
1
);
},
2
);
},
304
:
function
()
{
$
(
'
#loading #msg
'
).
html
(
"
We're done... cleaning up!
"
);
setTimeout
(
function
()
{
location
.
href
=
url
;},
3000
);
}
},
error
:
function
()
{
$
(
'
#loading #msg
'
).
html
(
"
Something went wrong
"
);
setTimeout
(
function
()
{
location
.
href
=
url
;},
1000
);
}
});
};
_lp
(
0
);
}
});
This diff is collapsed.
Click to expand it.
s
etu
p/upgrade.php
→
s
c
p/upgrade.php
+
0
−
0
View file @
56a8f924
File moved
This diff is collapsed.
Click to expand it.
setup/inc/class.attachment.migrate.php
deleted
100644 → 0
+
0
−
162
View file @
03a84301
<?php
/*********************************************************************
class.attachment.migrate.php
Attachment migration from file-based attachments in pre-1.7 to
database-backed attachments in osTicket v1.7. This class provides the
hardware to find and retrieve old attachments and move them into the new
database scheme with the data in the actual database.
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
include_once
(
INCLUDE_DIR
.
'class.file.php'
);
class
AttachmentMigrater
{
function
AttachmentMigrater
()
{
$this
->
queue
=
array
();
$this
->
current
=
0
;
$this
->
errors
=
0
;
$this
->
errorList
=
array
();
}
/**
* Identifies attachments in need of migration and queues them for
* migration to the new database schema.
*
* @see ::next() for output along the way
*
* Returns:
* TRUE/FALSE to indicate if migration finished without any errors
*/
function
start_migration
()
{
$this
->
findAttachments
();
$this
->
total
=
count
(
$this
->
queue
);
}
/**
* Process the migration for a unit of time. This will be used to
* overcome the execution time restriction of PHP. This instance can be
* stashed in a session and have this method called periodically to
* process another batch of attachments
*/
function
do_batch
(
$max
,
$time
=
20
)
{
$start
=
time
();
$this
->
errors
=
0
;
while
(
count
(
$this
->
queue
)
&&
$count
++
<
$max
&&
time
()
-
$start
<
$time
)
$this
->
next
();
# TODO: Log success/error indication of migration of attachments
return
(
!
$this
->
errors
);
}
function
queue
(
$fileinfo
)
{
$this
->
queue
[]
=
$fileinfo
;
}
function
getQueueLength
()
{
return
count
(
$this
->
queue
);
}
/**
* Processes the next item on the work queue. Emits a JSON messages to
* indicate current progress.
*
* Returns:
* TRUE/NULL if the migration was successful
*/
function
next
()
{
# Fetch next item -- use the last item so the array indices don't
# need to be recalculated for every shift() operation.
$info
=
array_pop
(
$this
->
queue
);
# Attach file to the ticket
if
(
!
(
$info
[
'data'
]
=
@
file_get_contents
(
$info
[
'path'
])))
{
# Continue with next file
return
$this
->
error
(
sprintf
(
'%s: Cannot read file contents'
,
$info
[
'path'
]));
}
# Get the mime/type of each file
# XXX: Use finfo_buffer for PHP 5.3+
$info
[
'type'
]
=
mime_content_type
(
$info
[
'path'
]);
if
(
!
(
$fileId
=
AttachmentFile
::
save
(
$info
)))
{
return
$this
->
error
(
sprintf
(
'%s: Unable to migrate attachment'
,
$info
[
'path'
]));
}
# Update the ATTACHMENT_TABLE record to set file_id
db_query
(
'update '
.
TICKET_ATTACHMENT_TABLE
.
' set file_id='
.
db_input
(
$fileId
)
.
' where attach_id='
.
db_input
(
$info
[
'attachId'
]));
# Remove disk image of the file. If this fails, the migration for
# this file would not be retried, because the file_id in the
# TICKET_ATTACHMENT_TABLE has a nonzero value now
if
(
!@
unlink
(
$info
[
'path'
]))
$this
->
error
(
sprintf
(
'%s: Unable to remove file from disk'
,
$info
[
'path'
]));
# TODO: Log an internal note to the ticket?
return
true
;
}
/**
* From (class Ticket::fixAttachments), used to detect the locations of
* attachment files
*/
/* static */
function
findAttachments
(){
global
$cfg
;
$res
=
db_query
(
'SELECT attach_id, file_name, file_key, Ti.created'
.
' FROM '
.
TICKET_ATTACHMENT_TABLE
.
' TA'
.
' JOIN '
.
TICKET_TABLE
.
' Ti ON Ti.ticket_id=TA.ticket_id'
.
' WHERE NOT file_id'
);
if
(
!
$res
)
{
return
$this
->
error
(
'Unable to query for attached files'
);
}
elseif
(
!
db_num_rows
(
$res
))
{
return
true
;
}
$dir
=
$cfg
->
getUploadDir
();
while
(
list
(
$id
,
$name
,
$key
,
$created
)
=
db_fetch_row
(
$res
))
{
$month
=
date
(
'my'
,
strtotime
(
$created
));
$info
=
array
(
'name'
=>
$name
,
'attachId'
=>
$id
,
);
$filename15
=
sprintf
(
"%s/%s_%s"
,
rtrim
(
$dir
,
'/'
),
$key
,
$name
);
$filename16
=
sprintf
(
"%s/%s/%s_%s"
,
rtrim
(
$dir
,
'/'
),
$month
,
$key
,
$name
);
//new destination.
if
(
file_exists
(
$filename15
))
{
$info
[
'path'
]
=
$filename15
;
}
elseif
(
file_exists
(
$filename16
))
{
$info
[
'path'
]
=
$filename16
;
}
else
{
# XXX Cannot find file for attachment
$this
->
error
(
sprintf
(
'%s: Unable to locate attachment file'
,
$name
));
# No need to further process this file
continue
;
}
# TODO: Get the size and mime/type of each file.
#
# NOTE: If filesize() fails and file_get_contents() doesn't,
# then the AttachmentFile::save() method will automatically
# estimate the filesize based on the length of the string data
# received in $info['data'] -- ie. no need to do that here.
#
# NOTE: The size is done here because it should be quick to
# lookup out of file inode already loaded. The mime/type may
# take a while because it will require a second IO to read the
# file data. To ensure this will finish before the
# max_execution_time, perform the type match in the ::next()
# method since the entire file content will be read there
# anyway.
$info
[
'size'
]
=
@
filesize
(
$info
[
'path'
]);
# Coroutines would be nice ..
$this
->
queue
(
$info
);
}
}
function
error
(
$what
)
{
$this
->
errors
++
;
$this
->
errorList
[]
=
$what
;
# Assist in returning FALSE for inline returns with this method
return
false
;
}
function
getErrors
()
{
return
$this
->
errorList
;
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
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