示例#1
0
 /**
  * Remove databases used in a draft publications
  *
  * @param    integer  	$identifier	Database ID	or name
  * @param    object  	$project 	Project object
  * @param    integer  	$version 	Database version
  * @return   bool
  */
 public function remove_database($identifier = 0, $project = NULL, $version = NULL)
 {
     if (!$identifier || $project == NULL) {
         $this->setError(Lang::txt('PLG_PROJECTS_DATABASES_ERROR_MISSING_ID'));
         return false;
     }
     if ($version === NULL || trim($version) == '') {
         $this->setError(Lang::txt('PLG_PROJECTS_DATABASES_ERROR_INVALID_VERSION'));
         return false;
     }
     $db = App::get('db');
     $ds_db = $this->get_ds_db($project->get('id'));
     // Load database record
     $objPD = new \Components\Projects\Tables\Database($db);
     if (!$objPD->loadRecord($identifier)) {
         $this->setError(Lang::txt('PLG_PROJECTS_DATABASES_ERROR_LOAD_RECORD'));
         return false;
     }
     // Remove record from database versions table
     $sql = 'DELETE FROM #__project_database_versions WHERE' . ' database_name = ' . $db->quote($objPD->database_name) . ' AND version = ' . $db->quote($version);
     $db->setQuery($sql);
     $db->query();
     // Remove database table
     $table_name = $objPD->database_name . '_' . $version;
     $sql = 'DROP TABLE ' . $table_name;
     $ds_db->setQuery($sql);
     return $ds_db->query();
 }
示例#2
0
 /**
  * Add/edit attachment
  *
  *
  * @return     boolean or error
  */
 public function addAttachment($database_name, $pub, $configs, $uid, $elementId, $element, $ordering = 1)
 {
     // Get database object and load record
     $objData = new \Components\Projects\Tables\Database($this->_parent->_db);
     $objData->loadRecord($database_name);
     $dbVersion = NULL;
     $objPA = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     if ($objPA->loadElementAttachment($pub->version_id, array('object_name' => $database_name), $elementId, $this->_name, $element->role)) {
         // Already attached
         $new = 0;
         if (!$objData->id) {
             // Original got deleted, can't do much
             return true;
         }
     } else {
         if (!$objData->id) {
             // Original database not found
             $this->setError(Lang::txt('Oups! Cannot attach selected database: database not found'));
             return false;
         }
         $objPA->publication_id = $pub->id;
         $objPA->publication_version_id = $pub->version_id;
         $objPA->type = $this->_name;
         $objPA->created_by = $uid;
         $objPA->created = Date::toSql();
         $objPA->role = $element->role;
         $new = 1;
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     if ($new) {
         $result = Event::trigger('projects.clone_database', array($database_name, $pub->_project, $configs->servePath));
         $dbVersion = $result && isset($result[0]) ? $result[0] : NULL;
     } else {
         $rtime = $objPA->modified ? strtotime($objPA->modified) : NULL;
         if ($objPA->object_id != $objData->id || strtotime($objData->updated) > $rtime) {
             // New database instance - need to clone again and get a new version number
             $result = Event::trigger('projects.clone_database', array($database_name, $pub->_project, $configs->servePath));
             $dbVersion = $result && isset($result[0]) ? $result[0] : NULL;
             $objPA->modified_by = $uid;
             $objPA->modified = Date::toSql();
         } else {
             // No changes
             $dbVersion = $objPA->object_revision;
         }
     }
     // Failed to clone
     if (!$dbVersion) {
         $this->_parent->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_FAILED_DB_CLONE'));
         return false;
     }
     $objPA->object_id = $objData->id;
     $objPA->object_name = $database_name;
     $objPA->object_revision = $dbVersion;
     $objPA->element_id = $elementId;
     $objPA->ordering = $ordering;
     $objPA->title = $objPA->title ? $objPA->title : $objData->title;
     // Build link path
     $objPA->path = 'dataviewer' . DS . 'view' . DS . 'publication:dsl' . DS . $database_name . DS . '?v=' . $dbVersion;
     if (!$objPA->store()) {
         $this->_parent->setError(Lang::txt('There was a problem attaching the database'));
         return false;
     }
     // Determine accompanying files and copy them in the right location
     $this->publishDataFiles($objData, $configs);
     return true;
 }
示例#3
0
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
// No direct access
defined('_HZEXEC_') or die;
// Get databases to choose from
$objPD = new \Components\Projects\Tables\Database($this->database);
$items = $objPD->getItems($this->model->get('id'), array());
$missing = array();
$shown = array();
// Attached item
$selected = NULL;
if ($this->primary && !empty($this->attachments)) {
    $selected = $this->attachments[0]->object_name;
}
// Build url
$route = $this->model->isProvisioned() ? 'index.php?option=com_publications' . '&task=submit' : 'index.php?option=com_projects' . '&alias=' . $this->model->get('alias');
$p_url = Route::url($route . '&active=databases');
?>
<ul id="c-browser" <?php 
if (count($items) == 0 && isset($this->attachments) && count($this->attachments) == 0) {
    echo 'class="hidden"';