зеркало из https://github.com/mozilla/pjs.git
Latest Addon MCV stuff
This commit is contained in:
Родитель
4d278d0d0b
Коммит
08c819c49f
|
@ -3,13 +3,13 @@
|
|||
class AddonsController extends AppController
|
||||
{
|
||||
var $name = 'Addons';
|
||||
var $components = array('Rdf', 'Versioncompare');
|
||||
var $components = array('Amo', 'Rdf', 'Versioncompare');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function index() {
|
||||
$this->set('addons', $this->Addon->findall());
|
||||
$this->set('addons', $this->Amo->addonTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,43 +18,20 @@ class AddonsController extends AppController
|
|||
*/
|
||||
function add($id = 0) {
|
||||
$this->layout = 'developers';
|
||||
$this->set('addonTypes', $this->Amo->addonTypes);
|
||||
|
||||
//Step 2: Parse uploaded file and if correct, display addon-wide information form
|
||||
if (isset($this->data['Addon']['add_step1'])) {
|
||||
if ($this->data['Addon']['file']['error'] === 0) {
|
||||
$uploadedFile = $this->data['Addon']['file']['tmp_name'];
|
||||
$tempLocation = REPO_PATH.'/temp/'.$this->data['Addon']['file']['name'];
|
||||
|
||||
if (move_uploaded_file($uploadedFile, $tempLocation)) {
|
||||
$uploadedFile = $tempLocation;
|
||||
chmod($uploadedFile, 0644);
|
||||
}
|
||||
else {
|
||||
$this->set('fileError', 'Could not move file');
|
||||
$this->render('add_step1');
|
||||
}
|
||||
|
||||
$manifestExists = false;
|
||||
|
||||
if ($zip = @zip_open($uploadedFile)) {
|
||||
while ($zipEntry = zip_read($zip)) {
|
||||
if (zip_entry_name($zipEntry) == 'install.rdf') {
|
||||
$manifestExists = true;
|
||||
if (zip_entry_open($zip, $zipEntry, 'r')) {
|
||||
$manifestData = zip_entry_read($zipEntry, zip_entry_filesize($zipEntry));
|
||||
zip_entry_close($zipEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
zip_close($zip);
|
||||
}
|
||||
|
||||
if ($manifestExists === true) {
|
||||
|
||||
}
|
||||
|
||||
$this->render('add_step2');
|
||||
//Check for model validation first (in step 1, this is just addon type)
|
||||
if (!$this->Addon->validates($this->data)) {
|
||||
$this->validateErrors();
|
||||
$this->set('fileError', '');
|
||||
$this->render('add_step1');
|
||||
die();
|
||||
}
|
||||
else {
|
||||
|
||||
//Check for file upload errors
|
||||
if ($this->data['Addon']['file']['error'] !== 0) {
|
||||
$this->Addon->invalidate('file');
|
||||
$fileErrors = array('1' => 'Exceeds maximum upload size',
|
||||
'2' => 'Exceeds maximum upload size',
|
||||
|
@ -65,6 +42,53 @@ class AddonsController extends AppController
|
|||
$this->set('fileError', $fileError);
|
||||
$this->render('add_step1');
|
||||
}
|
||||
|
||||
$fileName = $this->data['Addon']['file']['name'];
|
||||
$fileExtension = substr($fileName, strrpos($fileName, '.'));
|
||||
$allowedExtensions = array('.xpi', '.jar', '.src');
|
||||
//Check for file extenion match
|
||||
if (!in_array($fileExtension, $allowedExtensions)) {
|
||||
$this->Addon->invalidate('file');
|
||||
$this->set('fileError', 'Disallowed file extension ('.$fileExtension.')');
|
||||
$this->render('add_step1');
|
||||
die();
|
||||
}
|
||||
echo('test');
|
||||
//Move temporary file to repository
|
||||
$uploadedFile = $this->data['Addon']['file']['tmp_name'];
|
||||
$tempLocation = REPO_PATH.'/temp/'.$fileName;
|
||||
if (move_uploaded_file($uploadedFile, $tempLocation)) {
|
||||
$uploadedFile = $tempLocation;
|
||||
chmod($uploadedFile, 0644);
|
||||
}
|
||||
else {
|
||||
$this->Addon->invalidate('file');
|
||||
$this->set('fileError', 'Could not move file');
|
||||
$this->render('add_step1');
|
||||
}
|
||||
|
||||
//Find install.rdf in the package and get contents
|
||||
$manifestExists = false;
|
||||
|
||||
if ($zip = @zip_open($uploadedFile)) {
|
||||
while ($zipEntry = zip_read($zip)) {
|
||||
if (zip_entry_name($zipEntry) == 'install.rdf') {
|
||||
$manifestExists = true;
|
||||
if (zip_entry_open($zip, $zipEntry, 'r')) {
|
||||
$manifestData = zip_entry_read($zipEntry, zip_entry_filesize($zipEntry));
|
||||
zip_entry_close($zipEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
zip_close($zip);
|
||||
}
|
||||
|
||||
//Parse install.rdf
|
||||
if ($manifestExists === true) {
|
||||
|
||||
}
|
||||
|
||||
$this->render('add_step2');
|
||||
}
|
||||
elseif (isset($this->data['Addon']['add_step2'])) {
|
||||
$this->render('add_step3');
|
||||
|
@ -72,6 +96,7 @@ class AddonsController extends AppController
|
|||
elseif (isset($this->data['Addon']['add_step3'])) {
|
||||
$this->render('add_step4');
|
||||
}
|
||||
//Step 1: Add-on type and file upload
|
||||
else {
|
||||
$this->set('fileError', '');
|
||||
$this->render('add_step1');
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
class AmoComponent extends Object {
|
||||
var $addonTypes = array();
|
||||
|
||||
/**
|
||||
* Called automatically
|
||||
* @param object $controller
|
||||
*/
|
||||
function startup(&$controller) {
|
||||
$this->getAddonTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates addonTypes array from DB
|
||||
*/
|
||||
function getAddonTypes() {
|
||||
$addontype =& new Addontype();
|
||||
|
||||
$addonTypes = $addontype->findAll('', '', '', '', '', -1);
|
||||
foreach ($addonTypes as $k => $v) {
|
||||
$this->addonTypes[$addonTypes[$k]['Addontype']['id']] = $addonTypes[$k]['Addontype']['name'];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,14 +3,7 @@
|
|||
class Addon extends AppModel
|
||||
{
|
||||
var $name = 'Addon';
|
||||
var $belongsTo = array('Addontype' =>
|
||||
array('className' => 'Addontype',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'dependent' => false,
|
||||
'foreignKey' => 'addontype_id'
|
||||
)
|
||||
);
|
||||
var $belongsTo = array('Addontype');
|
||||
var $hasMany = array('Version' =>
|
||||
array('className' => 'Version',
|
||||
'conditions' => '',
|
||||
|
@ -72,6 +65,7 @@ class Addon extends AppModel
|
|||
'guid' => VALID_NOT_EMPTY,
|
||||
'name' => VALID_NOT_EMPTY,
|
||||
'description' => VALID_NOT_EMPTY,
|
||||
'addontype_id' => VALID_NUMBER
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,24 +3,21 @@
|
|||
class Addontype extends AppModel
|
||||
{
|
||||
var $name = 'Addontype';
|
||||
var $belongsTo = array('Addon' =>
|
||||
array('className' => 'Addon',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'foreignKey' => 'addontype_id'
|
||||
)
|
||||
);
|
||||
|
||||
var $hasMany = array('Tag' =>
|
||||
array('className' => 'Tag',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'foreignKey' => 'addontype_id',
|
||||
'dependent' => false,
|
||||
'exclusive' => false,
|
||||
'finderSql' => ''
|
||||
)
|
||||
|
||||
var $hasOne = array('Addon' =>
|
||||
array('className' => 'Addon',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'dependent' => false,
|
||||
'foreignKey' => 'addontype_id'
|
||||
),
|
||||
'Tag' =>
|
||||
array('className' => 'Tag',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'dependent' => false,
|
||||
'foreignKey' => 'addontype_id'
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Application extends AppModel
|
||||
{
|
||||
var $name = 'Application';
|
||||
var $hasMany = array('Tag' =>
|
||||
array('className' => 'Tag',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'foreignKey' => 'application_id',
|
||||
'dependent' => true,
|
||||
'exclusive' => false,
|
||||
'finderSql' => ''
|
||||
),
|
||||
'Appversion' =>
|
||||
array('className' => 'Appversion',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'foreignKey' => 'application_id',
|
||||
'dependent' => true,
|
||||
'exclusive' => false,
|
||||
'finderSql' => ''
|
||||
)
|
||||
);
|
||||
var $hasAndBelongsToMany = array('Version' =>
|
||||
array('className' => 'Version',
|
||||
'joinTable' => 'applications_versions',
|
||||
'foreignKey' => 'application_id',
|
||||
'associationForeignKey'=> 'version_id',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'unique' => false,
|
||||
'finderSql' => '',
|
||||
'deleteQuery'=> '',
|
||||
),
|
||||
);
|
||||
}
|
||||
?>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Tag extends AppModel
|
||||
{
|
||||
var $name = 'Tag';
|
||||
var $hasAndBelongsToMany = array('Addon' =>
|
||||
array('className' => 'Addon',
|
||||
'joinTable' => 'addons_tags',
|
||||
'foreignKey' => 'addon_id',
|
||||
'associationForeignKey'=> 'tag_id',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'limit' => '',
|
||||
'unique' => false,
|
||||
'finderSql' => '',
|
||||
'deleteQuery'=> '',
|
||||
)
|
||||
);
|
||||
var $belongsTo = array('Addontype' =>
|
||||
array('className' => 'Addontype',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'foreignKey' => 'addontype_id'
|
||||
),
|
||||
'Application' =>
|
||||
array('className' => 'Application',
|
||||
'conditions' => '',
|
||||
'order' => '',
|
||||
'foreignKey' => 'application_id'
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
|
@ -1,5 +1,7 @@
|
|||
<?=$html->formTag('/addons/add/', 'post', array('enctype'=>'multipart/form-data'))?>
|
||||
<?=$html->hidden('Addon/add_step1')?>
|
||||
Add-on Type: <?=$html->selectTag('Addon/addontype_id', $addonTypes)?><BR />
|
||||
<?=$html->tagErrorMsg('Addon/addontype_id', 'Please select the type of add-on you are submitting.')?>
|
||||
Max upload size: <?=ini_get('upload_max_filesize')?><BR />
|
||||
Add-on File: <?=$html->file('Addon/file')?><BR />
|
||||
<?=$html->tagErrorMsg('Addon/file', 'File error: '.$fileError)?>
|
||||
|
|
Загрузка…
Ссылка в новой задаче