/**
  * Overriddes the one in parent class 
  * this is because we sometimes have to do things when centroid coordinates have moved.
  */
 protected function refreshGeoAssociations($id)
 {
     c2cTools::log("Entering refreshGeoAssociations for outings linked with route {$id}");
     $associated_outings = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'ro');
     if (count($associated_outings)) {
         $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
         // we create new associations :
         //  (and delete old associations before creating the new ones)
         //  (and do not create outings-maps associations)
         foreach ($associated_outings as $outing) {
             $i = $outing['id'];
             if (!$outing['geom_wkt']) {
                 // replicate geoassoces from doc $id to outing $i and delete previous ones
                 // (because there might be geoassociations created by this same process)
                 // and we do not replicate map associations to outings
                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, false);
                 c2cTools::log("created {$nb_created} geo associations for outing N° {$i}");
                 $this->clearCache('outings', $i, false, 'view');
             }
         }
     }
 }
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
// needed for doctrine connection to work
sfContext::getInstance();
// Next Step : retrieve highest summits associated (in fact there should always be only one) with routes, and transfer summit geoassociations to route.
// WARNING: set correct id limits
// WARNING 2: routes must be consecutive.
$id = 44918;
$id_max = 57877;
while ($id <= $id_max) {
    echo "Computing associations for route {$id} ... \n";
    // if associations with areas for current doc already existed, delete them
    //$deleted = GeoAssociation::deleteAllFor($id, array('dr', 'dc', 'dd', 'dm'));
    //if ($deleted) echo "Deleted $deleted already existing geoassociations. \n";
    // get all associated regions (3+maps) with this summit:
    //$summit_id is the id of associated summit with route $id
    $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'), 'sr');
    // summit-route
    foreach ($associated_docs as $doc) {
        if ($doc['module'] == 'summits') {
            $summit_id = $doc['id'];
        }
    }
    $associations = GeoAssociation::findAllAssociations($summit_id, array('dr', 'dc', 'dd', 'dm'));
    // replicate them with route_id instead of summit_id:
    foreach ($associations as $ea) {
        $a = new GeoAssociation();
        $a->doSaveWithValues($id, $ea->get('linked_id'), $ea->get('type'));
        echo "Created association with " . $ea->get('linked_id') . " \n";
        unset($a);
    }
    $id++;
 public function setEditFormInformation()
 {
     parent::setEditFormInformation();
     if (!$this->new_document) {
         // retrieve associated articles, for use in the MW contest checkbox
         $prefered_cultures = $this->getUser()->getCulturesForDocuments();
         $id = $this->getRequestParameter('id');
         $this->associated_articles = Association::findAllAssociatedDocs($id, array('id'), 'oc');
     }
 }
 public function executeDelete()
 {
     $referer = $this->getRequest()->getReferer();
     if ($id = $this->getRequestParameter('id')) {
         $document = Document::find($this->model_class, $id, array('module'));
         if (!$document) {
             $this->setErrorAndRedirect('Document does not exist', $referer);
         }
         $module = $document->get('module');
         $this->deleteLinkedFile($id);
         $nb_dv_deleted = Document::doDelete($id);
         c2cTools::log("executeDelete: deleted document {$id} and its {$nb_dv_deleted} versions (all langs taken into account)");
         if ($nb_dv_deleted) {
             // cache clearing for deleted doc in every lang, without whatsnew:
             $this->clearCache($module, $id, false);
             // find all associated docs
             $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
             foreach ($associated_docs as $doc) {
                 // clear their view cache
                 $this->clearCache($doc['module'], $doc['id'], false, 'view');
             }
             // remove all general associations concerned by this document
             $deleted = Association::deleteAll($id);
             c2cTools::log("executeDelete: deleted {$deleted} general associations concerning this doc");
             // find all geo associated docs
             $associated_docs = GeoAssociation::findAllAssociatedDocs($id, array('id', 'module'));
             foreach ($associated_docs as $doc) {
                 // clear their view cache
                 $this->clearCache($doc['module'], $doc['id'], false, 'view');
             }
             // remove all geo associations concerned by this document
             $deleted += GeoAssociation::deleteAll($id);
             c2cTools::log("executeDelete: deleted {$deleted} general associations concerning this doc");
             // flash info:
             $this->setNoticeAndRedirect('Document deleted', "@default_index?module={$module}");
         } else {
             $this->setErrorAndRedirect('Document could not be deleted', $referer);
         }
     } else {
         $this->setErrorAndRedirect('Could not understand your request', $referer);
     }
 }
 /**
  * Executes delete action
  * Checks if there are some associated routes with only this summit.
  * If not, then call the parent default delete action. 
  * If yes, calls error and redirect
  */
 public function executeDelete()
 {
     $referer = $this->getRequest()->getReferer();
     if ($id = $this->getRequestParameter('id')) {
         // Get all associated documents
         $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
         if ($associated_docs) {
             // Initialise the list of routes only associated to this summit
             $single_summit_route_list = array();
             // Check if any associated doc is a route
             foreach ($associated_docs as $doc) {
                 if ($doc['module'] == 'routes') {
                     // if we found an associated route, check if it is associated to several summits
                     $route_associated_docs = Association::findAllAssociatedDocs($doc['id'], array('id', 'module'));
                     if ($route_associated_docs) {
                         // Check if any associated doc to the route is a summit different from the one we want to delete
                         $multiple_summit = False;
                         foreach ($route_associated_docs as $route_associated_doc) {
                             // There's an associated summit which is different from the one we want to delete
                             if ($route_associated_doc['module'] == 'summits' && $route_associated_doc['id'] != $id) {
                                 $multiple_summit = True;
                                 break;
                             }
                         }
                         if (!$multiple_summit) {
                             // this route has only one summit: the one we want to delete
                             $single_summit_route_list[] = $doc['id'];
                         }
                     } else {
                         // shouldn't reach here, as the route we found should at least be associated to the summit that should (or not) be deleted
                         $this->setErrorAndRedirect('Document could not be deleted', $referer);
                     }
                 }
             }
             if (!empty($single_summit_route_list)) {
                 // If we found an associated route which has only one summit, we do not delete the summit
                 $this->setErrorAndRedirect('Document could not be deleted because there would be orphean routes%1%', $referer, array('%1%' => '<li><ul>' . implode('</ul><ul>', $single_summit_route_list) . '</ul></li>'));
             }
         }
         // If we reach here, then either there were no associated docs, or none of them was a route.
         parent::executeDelete();
     } else {
         $this->setErrorAndRedirect('Could not understand your request', $referer);
     }
 }
Example #6
0
     }
     if ($max_ele > 0) {
         $item->addChild('geom', "{$lon},{$lat}");
         $item->addChild('elevation', $max_ele);
     } else {
         // could not find any geolocalized route to link
         // => we go to the next step : find highest associated summits to these routes
         $coords = Route::findHighestAssociatedSummitCoords($associated_routes);
         if ($coords['ele'] > 0) {
             if (strlen($coords['lon']) && strlen($coords['lat'])) {
                 $item->addChild('geom', $coords['lon'] . ',' . $coords['lat']);
             }
             $item->addChild('elevation', $coords['ele']);
         }
     }
 } elseif ($associated_sites = Association::findAllAssociatedDocs($id, $fields = array('id', 'lon', 'lat', 'elevation'), 'to')) {
     // find highest site
     $max_ele = 0;
     foreach ($associated_sites as $site) {
         if (($ele = $site['elevation']) && $ele > $max_ele && ($lon = $site['lon']) && ($lat = $site['lat'])) {
             $highest_site = $site;
             $max_ele = $site['elevation'];
         }
     }
     if ($max_ele > 0) {
         $item->addChild('geom', "{$lon},{$lat}");
         $item->addChild('elevation', $max_ele);
     }
 }
 $item->addChild('date', $object->get('date'));
 $item->addChild('lang', $lang);
Example #7
0
function import_new_geometry()
{
    global $conn, $comment, $is_map, $is_new_document, $culture, $name, $map_editor, $map_scale, $map_code, $keepassociations, $region_type, $newgeomtext, $no_oldgeom, $document_id, $a_type, $fullwipe, $oldgeom, $newgeom, $prgmsg;
    info("Importing the new geometry...\n");
    try {
        $conn->beginTransaction();
        $history_metadata = new HistoryMetadata();
        $history_metadata->setComment(isset($comment) ? $comment : ($is_new_document ? 'Imported new ' . ($is_map ? 'map' : 'area') : 'Updated geometry'));
        $history_metadata->set('is_minor', false);
        $history_metadata->set('user_id', 2);
        // C2C user
        $history_metadata->save();
        if ($is_new_document) {
            $doc = $is_map ? new Map() : new Area();
            $doc->setCulture($culture);
            $doc->set('name', $name);
            if ($is_map) {
                $doc->set('editor', $map_editor);
                $doc->set('scale', $map_scale);
                $doc->set('code', $map_code);
            } else {
                $doc->set('area_type', $region_type);
            }
        } else {
            $doc = Document::find($is_map ? 'Map' : 'Area', $document_id);
            $name = $doc->get('name');
            if (!$is_map) {
                $region_type = $doc->get('area_type');
            }
        }
        $doc->set('geom_wkt', $newgeomtext);
        $doc->save();
        info("Geometry uploaded.\n");
        if ($keepassociations) {
            exit;
        }
        if ($is_new_document) {
            $document_id = $doc->get('id');
        }
        // $conn->commit();
        // $conn->beginTransaction();
        if ($is_map) {
            $a_type = 'dm';
        } else {
            switch ($region_type) {
                case 1:
                    // range
                    $a_type = 'dr';
                    break;
                case 2:
                    // country
                    $a_type = 'dc';
                    break;
                case 3:
                    // dept
                    $a_type = 'dd';
                    break;
            }
        }
        // Some explanation for the following queries:
        // - && operator is used to limit docs to the one whose bouding boxes overlap (it uses spatial index)
        // - ST_Within and ST_Intersects are used to work on the actual geometries
        // - ST_Within apears to be faster, so we use it for 'points' (like summits, huts etc), but we have
        //   to use ST_Intersects for 'geometries' (like outings, maps etc)
        // - we only use a buffer of 200m for areas (because of boundaries imprecision), but not for maps
        // - areas are not linked together
        // - maps are not linked to outings, users, and other maps
        // if it is a new document, we create geoassociations for the whole geometry
        // but if its an updated one, we only create geoassociations for the part of the
        // new geometry that does not intersect with the old one
        if ($is_new_document || $no_oldgeom || $fullwipe) {
            // retrieve geom from the database
            $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $geomqueryb = '(SELECT buffer(geom, 200) FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $queryparam = array($document_id, $document_id);
        } else {
            $queryparam = array();
            $creategeom = $conn->standaloneQuery("SELECT ST_Difference('{$newgeom}', '{$oldgeom}')")->fetchAll();
            $creategeomb = $conn->standaloneQuery("SELECT ST_Difference(buffer('{$newgeom}', 200), buffer('{$oldgeom}', 200))")->fetchAll();
            $creategeom = $creategeom[0]['st_difference'];
            $creategeomb = $creategeomb[0]['st_difference'];
            $geomquery = "'{$creategeom}'";
            $geomqueryb = "'{$creategeomb}'";
        }
        // for maps, we don't use buffer at all
        if ($is_map) {
            $geomqueryb = $geomquery;
        }
        $queries = array();
        // point geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Within(geom, {$geomqueryb}) " . "AND module IN('summits', 'huts', 'sites', 'parkings', 'products', 'portals', 'images'" . ($is_map ? '' : ", 'users'") . ')', $queryparam);
        // multipoint geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Intersects(geom, {$geomqueryb}) AND module" . ($is_map ? "='routes'" : " IN('routes', 'outings')"), $queryparam);
        // for maps areas associations, we always compute 'full wipe', without buffer
        $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomquery} " . "AND ST_Intersects(geom, {$geomquery}) AND module='" . ($is_map ? 'areas' : 'maps') . "'", array($document_id, $document_id));
        $results_a = array();
        foreach ($queries as $query) {
            $results_a[] = $conn->standaloneQuery($query[0], $query[1])->fetchAll();
        }
        $results = array();
        foreach ($results_a as $results_set) {
            foreach ($results_set as $d) {
                $results[] = $d;
            }
        }
        $prgmsg = "Create new associations...";
        info($prgmsg);
        $tot = count($results);
        foreach ($results as $i => $d) {
            progression($i, $tot);
            // Apparently in some cases, we ar trying to create associations that
            // already exist, so we check first
            if (!GeoAssociation::find($document_id, $d['id'], null, false)) {
                $a = new GeoAssociation();
                $created[$d['module']] = isset($created[$d['module']]) ? $created[$d['module']] + 1 : 1;
                // for map - area geoassociations, links must not be dm but dr, dc, dd...
                if ($is_map && $d['module'] === 'areas') {
                    $area = Document::find('Area', $d['id']);
                    switch ($area->get('area_type')) {
                        case 1:
                            // range
                            $t_a_type = 'dr';
                            break;
                        case 2:
                            // country
                            $t_a_type = 'dc';
                            break;
                        case 3:
                            // dept
                            $t_a_type = 'dd';
                            break;
                    }
                    $a->doSaveWithValues($document_id, $d['id'], $t_a_type);
                } else {
                    $a->doSaveWithValues($d['id'], $document_id, $a_type);
                }
            }
            // inherited docs: we add geoassociations for the 'inherited docs' from sites, routes and summits
            // but not if they already have a geometry (gps track)
            switch ($d['module']) {
                case 'sites':
                case 'routes':
                    if ($is_map) {
                        break;
                    }
                    // we do not link maps to outings
                    $associated_outings = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), $d['module'] === 'routes' ? 'ro' : 'to');
                    if (count($associated_outings)) {
                        foreach ($associated_outings as $outing) {
                            if (!$outing['geom_wkt'] && GeoAssociation::find($outing['id'], $document_id, $a_type) === false) {
                                // we create geoassociation (if it already existed, it has been deleted before in the script)
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($outing['id'], $document_id, $a_type);
                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                            }
                        }
                    }
                    break;
                case 'summits':
                    // if summit is of type raid, we should not try to update its routes and outings summit_type=5
                    $summit = Document::find('Summit', $d['id']);
                    if ($summit->get('summit_type') == 5) {
                        break;
                    }
                    $associated_routes = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), 'sr');
                    if (count($associated_routes)) {
                        foreach ($associated_routes as $route) {
                            $i = $route['id'];
                            if (!$route['geom_wkt'] && GeoAssociation::find($i, $document_id, $a_type) === false) {
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($i, $document_id, $a_type);
                                $created['routes'] = isset($created['routes']) ? $created['routes'] + 1 : 1;
                                if (!$is_map) {
                                    $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                                    if (count($associated_outings)) {
                                        foreach ($associated_outings as $outing) {
                                            $j = $outing['id'];
                                            if (!$outing['geom_wkt'] && GeoAssociation::find($j, $document_id, $a_type) === false) {
                                                $a = new GeoAssociation();
                                                $a->doSaveWithValues($j, $document_id, $a_type);
                                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }
        info("\n");
        $conn->commit();
        if (isset($created)) {
            associations_result($created);
        }
        if ($is_new_document) {
            info('Added new ' . ($is_map ? 'map' : 'area') . " {$name} ({$document_id})\n");
        } else {
            info('Updated ' . ($is_map ? 'map' : 'area') . " ({$document_id})\n");
        }
    } catch (Exception $e) {
        $conn->rollback();
        throw $e;
    }
}
 protected function endEdit()
 {
     if ($this->success) {
         // before redirecting view, we check if either the name, elevation or geolocalization of the hut
         // has changed and pass on those changes to the 'ghost summit'
         $hut_doc = $this->document;
         $summit_doc = $hut_doc->getGhostSummit();
         // check wether elevation, name or geometry of the hut has changed, and
         // change accordingly the ghost summit if that's the case
         if ($summit_doc != false) {
             $geom_changed = $hut_doc->get('lat') !== $summit_doc->get('lat') || $hut_doc->get('lon') !== $summit_doc->get('lon');
             if ($hut_doc->get('elevation') !== $summit_doc->get('elevation') || $hut_doc->get('name') !== $summit_doc->get('name') || $geom_changed) {
                 c2cTools::log('Updating ghost summit of hut');
                 $id = $summit_doc->get('id');
                 $conn = sfDoctrine::Connection();
                 try {
                     $conn->beginTransaction();
                     $history_metadata = new HistoryMetadata();
                     $history_metadata->set('is_minor', false);
                     $history_metadata->set('user_id', $this->getUser()->getId());
                     $history_metadata->setComment('Synchronize summit to associated hut');
                     $history_metadata->save();
                     $summit_doc->set('name', $hut_doc->get('name'));
                     $summit_doc->set('lon', $hut_doc->get('lon'));
                     $summit_doc->set('lat', $hut_doc->get('lat'));
                     $summit_doc->set('elevation', $hut_doc->get('elevation'));
                     $summit_doc->save();
                     $conn->commit();
                     if ($geom_changed) {
                         // TODO idea here is to call the refreshGeoAssociations
                         // from summitsActions but we can't call it. In order not to
                         // change the whole mechanism for refreshAssociations, we kinda copy paste
                         // the function here, but this should be improved / factorized
                         // refer to it to understand what is done here
                         $associated_routes = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'sr');
                         if (count($associated_routes)) {
                             $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
                             foreach ($associated_routes as $route) {
                                 $i = $route['id'];
                                 if (!$route['geom_wkt']) {
                                     $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, true);
                                     $this->clearCache('routes', $i, false, 'view');
                                     $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                                     if (count($associated_outings)) {
                                         $geoassociations2 = GeoAssociation::findAllAssociations($i, null, 'main');
                                         foreach ($associated_outings as $outing) {
                                             $j = $outing['id'];
                                             if (!$outing['geom_wkt']) {
                                                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations2, $j, true, false);
                                                 c2cTools::log("created {$nb_created} geo associations for outing N° {$j}");
                                                 $this->clearCache('outings', $j, false, 'view');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } catch (Exception $e) {
                     $conn->rollback();
                     // TODO It is ok to signal the failure, but anyway, the hut doc has been updated
                     // so there is much room for improvement here :)
                     return $this->setErrorAndRedirect("Failed to synchronize summit", '@document_edit?module=huts&id=' . $hut_doc->getId() . '&lang=' . $hut_doc->getCulture());
                 }
             }
         }
         parent::endEdit();
         // redirect to document view
     }
 }
 public function executeManageimages()
 {
     if (!$this->getUser()->isConnected()) {
         $referer = $this->getRequest()->getReferer();
         $this->setErrorAndRedirect('You need to login to access this page', $referer);
     }
     $user_id = $this->getUser()->getId();
     // logged user id
     $this->pager = new c2cDoctrinePager('Image', c2cTools::mobileVersion() ? sfConfig::get('app_list_mobile_maxline_number') : sfConfig::get('app_list_maxline_number'));
     $q = $this->pager->getQuery();
     $q->select('i.id, i.filename, i.image_type, ii.name, ii.culture')->from('Image i')->leftJoin('i.associations a ON i.id = a.linked_id')->leftJoin('i.ImageI18n ii')->leftJoin('i.versions v')->leftJoin('v.history_metadata hm');
     $where = 'i.image_type = 2 AND v.version = 1 AND hm.user_id = ?';
     $document_type = $this->getRequestParameter('dtyp');
     if (!empty($document_type)) {
         if ($document_type <= 1) {
             $types = array('ai', 'mi', 'bi', 'hi', 'pi', 'ri', 'ti', 'si');
         } else {
             $types = array('oi', 'ui');
         }
         $where .= " AND a.type IN ( '" . implode("', '", $types) . "' )";
     } else {
         $document_type = $this->getRequestParameter('ctyp');
         if (!empty($document_type)) {
             $q->leftJoin('a.Article c');
             if ($document_type <= 1) {
                 $document_type = 1;
             } else {
                 $document_type = 2;
             }
             $where .= " AND a.type = 'ci' AND c.article_type = {$document_type}";
         }
     }
     $q->where($where, array($user_id));
     $q->orderBy('i.id DESC');
     $page = $this->getRequestParameter('page', 1);
     $this->pager->setPage($page);
     $this->pager->init();
     $this->page = $page;
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // images management
         $switch = $this->getRequestParameter('switch');
         $lang = $this->getUser()->getCulture();
         if (empty($switch)) {
             return $this->setNoticeAndRedirect('No image has been edited', "/users/manageimages?module=users&page={$page}");
         }
         $conn = sfDoctrine::Connection();
         $conn->beginTransaction();
         $history_metadata = new HistoryMetadata();
         $history_metadata->setComment('Switch to collaborative license');
         $history_metadata->set('is_minor', true);
         $history_metadata->set('user_id', $user_id);
         $history_metadata->save();
         foreach ($switch as $image_id) {
             // verify id corresponds to an image created by the user
             $img = Doctrine_Query::create()->select('i.id')->from('Image i')->leftJoin('i.versions v')->leftJoin('v.history_metadata hm')->where('v.version = 1 AND hm.user_id = ? AND i.id = ?', array($user_id, $image_id))->execute();
             if (empty($img)) {
                 $conn->rollback();
                 return $this->setNoticeAndRedirect('You do not have the right to change the license of theses images', "/users/manageimages?module=users&page={$page}");
             }
             $db_doc = Document::find('Image', $image_id);
             $db_doc->set('image_type', 1);
             $db_doc->save();
             // clear cache
             $this->clearCache('images', $image_id, false, 'view');
             $associated_docs = Association::findAllAssociatedDocs($image_id, array('id', 'module'));
             foreach ($associated_docs as $doc) {
                 // clear their view cache
                 $this->clearCache($doc['module'], $doc['id'], false, 'view');
             }
         }
         // apply modifications if everything went fine
         $conn->commit();
         return $this->setNoticeAndRedirect('Your images have been successfully updated', "/users/manageimages?module=users&page={$page}");
     } else {
         // display form
         $this->setPageTitle($this->__('User image management'));
     }
 }
Example #10
0
 public function executeRotate()
 {
     $id = $this->getRequestParameter('id');
     $referer = $this->getRequest()->getReferer();
     $degrees = (int) $this->getRequestParameter('degrees');
     if ($degrees !== 90 && $degrees !== -90) {
         $referer = $this->getRequest()->getReferer();
         $this->setErrorAndRedirect('Bad rotation value', $referer);
     }
     $doc = Document::find('Image', $id);
     $this->document = $doc;
     if (!$doc) {
         $this->setErrorAndRedirect('Image not found', $referer);
     }
     // check if the user has the right for editing the image
     $this->filterAuthorizedPeople($id);
     $temp_dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_temp_directory_name') . DIRECTORY_SEPARATOR;
     $upload_dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_directory_name') . DIRECTORY_SEPARATOR;
     list($filename, $extension) = Images::getFileNameParts($doc->getFilename());
     $unique_filename = c2cTools::generateUniqueName();
     // because images on production get migrated after a while on a different server
     // we need to check if the file exists on disk before trying to rotate the image
     if (!file_exists($upload_dir . $filename . $extension)) {
         $this->setErrorAndRedirect('Image cannot be rotated anymore', $referer);
     }
     Images::rotateImage($upload_dir . $filename . $extension, $temp_dir . $unique_filename . $extension, $degrees);
     Images::generateThumbnails($unique_filename, $extension, $temp_dir);
     if (!Images::moveAll($unique_filename . $extension, $temp_dir, $upload_dir)) {
         $this->setErrorAndRedirect('Rotation failed', $referer);
     }
     // we don't create a new image document version, instead we directly
     // update the filename field and clear cache
     // We need to change it everytime it appears, since we could have several image versions
     // with same filename (if non-i18n data like categroies has been changed)
     try {
         $conn = sfDoctrine::Connection();
         $conn->beginTransaction();
         Doctrine_Query::create()->update('ImageArchive ia')->set('ia.filename', '?')->where('ia.id = ? AND ia.filename = ?', array($unique_filename . $extension, $id, $filename . $extension))->execute();
         $conn->commit();
         // Delete old files
         Images::removeAll($filename . $extension, $upload_dir);
     } catch (Exception $e) {
         $conn->rollback();
         // delete rotated images
         Images::removeAll($unique_filename . $extension, $upload_dir);
         $this->setErrorAndRedirect('Rotation failed', $referer);
     }
     // clear cache of current doc
     $this->clearCache('images', $id);
     // clear views of the associated docs in every language (content+interface):
     $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
     foreach ($associated_docs as $doc) {
         // clear their view cache
         $this->clearCache($doc['module'], $doc['id'], false, 'view');
     }
     // redirect to view
     $this->setNoticeAndRedirect('Image rotated successfully', $referer);
 }
Example #11
0
    // Remove private data
    Doctrine_Query::create()->delete()->from('UserPrivateData')->addWhere("id = '{$userid_to_wipe}'")->execute();
    $conn->commit();
} catch (Exception $e) {
    $conn->rollback();
    echo "A problem occured during merging\n";
    throw $e;
}
// Clear cache - We cannot use function from c2cActions since it is protected
$cache_dir = sfConfig::get('sf_root_cache_dir') . '/frontend/*/template/*/all';
$cache_dir .= sfConfig::get('sf_no_script_name') ? '/' : '/*/';
//c2cActions::clearCache('users', $userid_to_wipe, false);
$toRemove[] = "users/*/id/{$userid_to_wipe}/*";
//c2cActions::clearCache('users', $userid_to_remain, false);
$toRemove[] = "users/*/id/{$userid_to_remain}/*";
// find all docs associated to user_id_to_remain and clear the cache
$associated_docs = Association::findAllAssociatedDocs($userid_to_remain, array('id', 'module'));
foreach ($associated_docs as $doc) {
    //c2cActions::clearCache($doc['module'], $doc['id'], false, 'view');
    $toRemove[] = "{$doc['module']}/view/id/{$doc['id']}/*";
}
// find all geo associated docs
$associated_docs = GeoAssociation::findAllAssociatedDocs($userid_to_remain, array('id', 'module'));
foreach ($associated_docs as $doc) {
    //c2cActions::clearCache($doc['module'], $doc['id'], false, 'view');
    $toRemove[] = "{$doc['module']}/view/id/{$doc['id']}/*";
}
foreach ($toRemove as $item) {
    sfToolkit::clearGlob($cache_dir . $item);
}
echo "Users successfully merged\n";