Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for mssql database, add missing defaults, catch exceptions #11

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 85 additions & 21 deletions plugins/sampledata/testing/testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,23 @@ public function onAjaxSampledataApplyStep1()
'access' => $access,
'created_user_id' => $user->id,
'language' => '*',
'description' => '',
);

if (!$model->save($tag))
try
{
JFactory::getLanguage()->load('com_tags');
if (!$model->save($tag))
{
JFactory::getLanguage()->load('com_tags');
throw new Exception(JText::_($model->getError()));
}
}
catch (Exception $e)
{

$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 1, JText::_($model->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 1, $e->getMessage());

return $response;
}
Expand All @@ -150,14 +159,22 @@ public function onAjaxSampledataApplyStep1()
'access' => $access,
'created_user_id' => $user->id,
'language' => '*',
'description' => '',
);

if (!$model->save($tag))
try
{
if (!$model->save($tag))
{
JFactory::getLanguage()->load('com_tags');
throw new Exception(JText::_($model->getError()));
}
}
catch (Exception $e)
{
JFactory::getLanguage()->load('com_tags');
$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 1, JText::_($model->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 1, $e->getMessage());

return $response;
}
Expand Down Expand Up @@ -254,19 +271,28 @@ public function onAjaxSampledataApplyStep2()
foreach ($clients as $client)
{
// Set values which are always the same.
$client['id'] = 0;
$client['email'] = 'banner@example.com';
$client['state'] = 1;
$client['id'] = 0;
$client['email'] = 'banner@example.com';
$client['state'] = 1;
$client['metakey'] = '';
$client['extrainfo'] = '';

$clientTable->load();
$clientTable->bind($client);

if (!$clientTable->store())
try
{
if (!$clientTable->store())
{
JFactory::getLanguage()->load('com_banners');
throw new Exception(JText::_($clientTable->getError()));
}
}
catch (Exception $e)
{
JFactory::getLanguage()->load('com_banners');
$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 2, JText::_($clientTable->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 2, $e->getMessage());

return $response;
}
Expand Down Expand Up @@ -313,6 +339,8 @@ public function onAjaxSampledataApplyStep2()
$banner['type'] = 0;
$banner['state'] = 1;
$banner['alias'] = JApplicationHelper::stringURLSafe($banner['name']);
$banner['custombannercode'] = '';
$banner['metakey'] = '';
$banner['purchase_type'] = -1;
$banner['created_by'] = $user->id;
$banner['created_by_alias'] = 'Joomla';
Expand All @@ -321,12 +349,19 @@ public function onAjaxSampledataApplyStep2()
$bannerTable->load();
$bannerTable->bind($banner);

if (!$bannerTable->store())
try
{
if (!$bannerTable->store())
{
JFactory::getLanguage()->load('com_banners');
throw new Exception(JText::_($bannerTable->getError()));
}
}
catch (Exception $e)
{
JFactory::getLanguage()->load('com_banners');
$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 2, JText::_($bannerTable->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 2, $e->getMessage());

return $response;
}
Expand Down Expand Up @@ -1232,6 +1267,11 @@ public function onAjaxSampledataApplyStep4()
$fields = array('con_position', 'address', 'suburb', 'state', 'country', 'postcode', 'telephone', 'fax',
'misc', 'sortname1', 'sortname2', 'sortname3', 'email_to', 'image');

// Temporary, they are waiting for PR #14112
$fields[] = 'metakey';
$fields[] = 'metadesc';
$contact['metadata'] = '{}';

foreach ($fields as $field)
{
if (!isset($contact[$field]))
Expand Down Expand Up @@ -1269,12 +1309,19 @@ public function onAjaxSampledataApplyStep4()
);
}

if (!$model->save($contact))
try
{
if (!$model->save($contact))
{
JFactory::getLanguage()->load('com_contact');
throw new Exception(JText::_($model->getError()));
}
}
catch (Exception $e)
{
JFactory::getLanguage()->load('com_contact');
$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 4, JText::_($model->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 4, $e->getMessage());

return $response;
}
Expand Down Expand Up @@ -1389,12 +1436,26 @@ public function onAjaxSampledataApplyStep5()
$newsfeed['images'] = '';
$newsfeed['catid'] = $catIdsLevel1[0];

if (!$model->save($newsfeed))
// Temporary, it should be fixed in other place
$newsfeed['metakey'] = '';
$newsfeed['metadesc'] = '';
$newsfeed['xreference'] = '';
$newsfeed['metadata'] = '{}';
$newsfeed['params'] = '{}';

try
{
if (!$model->save($newsfeed))
{
JFactory::getLanguage()->load('com_newsfeeds');
throw new Exception(JText::_($model->getError()));
}
}
catch (Exception $e)
{
JFactory::getLanguage()->load('com_newsfeeds');
$response = array();
$response['success'] = false;
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 5, JText::_($model->getError()));
$response['message'] = JText::sprintf('PLG_SAMPLEDATA_TESTING_STEP_FAILED', 5, $e->getMessage());

return $response;
}
Expand Down Expand Up @@ -4555,6 +4616,9 @@ private function addArticles(array $articles)
$article['alias'] = JApplicationHelper::stringURLSafe($article['title']);
$article['language'] = '*';
$article['associations'] = array();
$article['metakey'] = '';
$article['metadesc'] = '';
$article['xreference'] = '';

// Set state to published if not set.
if (!isset($article['state']))
Expand Down